zoukankan      html  css  js  c++  java
  • WebAPI服务端内嵌在CS程序里面

    有时候我们不需要将WebAPI发布到iis上运行,需要将webapi内嵌到cs程序内部,随程序一起启动,其实比较简单,需要一个类,如下

     public class Startup
        {
            public static HttpSelfHostServer m_serverhost = null;
            public static void IniWebApi()
            {
                HttpSelfHostConfiguration _config = new HttpSelfHostConfiguration("http://localhost:4545");
                _config.MaxReceivedMessageSize=int.MaxValue;
                _config.MaxBufferSize = int.MaxValue;
                _config.Routes.MapHttpRoute(
                 name: "DefaultApinew",
                 routeTemplate: "api/{controller}/{action}/{id}",
                 defaults: new { id = RouteParameter.Optional }
             );
    
                //start 
                m_serverhost = new HttpSelfHostServer(_config);
                m_serverhost.OpenAsync().Wait();
            }
        }

    然后启动的时候 调用IniWebApi函数就可以了

  • 相关阅读:
    js在微信、微博、QQ、Safari唤起App的解决方案
    js根据ip自动获取地址(省市区)
    css行内省略号、垂直居中
    PAT1006
    PAT1005
    PAT1004
    PAT1003
    PAT1002
    PAT1001
    latex中的空格
  • 原文地址:https://www.cnblogs.com/bfyx/p/9234417.html
Copyright © 2011-2022 走看看