热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

c#实现网页(WebPage)和本地程序(LocalApp)之间的动态调用

场景说明:例如使用网站时,需要通过第三方程序获取本机的串口获取信息,服务端无法直接获取,需要通过本地程序解决方案:通过本地exe程序通过监听http请求的特定端口,然后实现在本地e

场景说明:例如使用网站时,需要通过第三方程序获取本机的串口获取信息,服务端无法直接获取,需要通过本地程序

解决方案:通过本地exe程序通过监听http请求的特定端口,然后实现在本地exe调用第三方程序

第三方程序例如:DLL插件,用于调用电脑本地硬件(打印机、扫描仪、读卡器等)或者通过DLL插件和第三方项目程序进行交互。

                             Exe可执行程序,主要用于集成第三方程序。

主要实现逻辑(参考:https://github.com/wrxiang/WebRunLocal)

using System;
using System.Net.Http;
using System.ServiceModel;
using System.Web.Http;
using System.Web.Http.SelfHost;
namespace RestController
{
class Program
{
static void Main(string[] args)
{
var cOnfig= new HttpSelfHostConfiguration("http://localhost:12357");
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{action}");
using (HttpSelfHostServer server = new HttpSelfHostServer(config))
{
server.OpenAsync().Wait();
Console.WriteLine("Press Enter to quit.");
Console.ReadLine();
}
}
}
public class TestController : ApiController
{
[HttpPost]
public HttpResponseMessage PostMethodFactory()
{
return new HttpResponseMessage();
}
}
}

  



推荐阅读
author-avatar
花神
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有