zoukankan      html  css  js  c++  java
  • 类库服务寄宿到WebHost

    1.该Demo中包含一个类库项目、一个空的WebForm项目

    2.新建WebForm项目

    3.全局路由中注册类库服务

    public class Global : System.Web.HttpApplication
        {
            protected void Application_Start(object sender, EventArgs e)
            {
                RegisterRoutes();
    
    
                System.ServiceModel.WebHttpBinding bing = new System.ServiceModel.WebHttpBinding();
                bing.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas() { MaxStringContentLength = 2147483647 }; //(更改这个数字) 
                bing.MaxReceivedMessageSize = 2147483647;
            }
            private void RegisterRoutes()
            {
                RouteTable.Routes.Add(new ServiceRoute("blog", new WebServiceHostFactory(), typeof(ClientApiTest.Class1)));
    
            }
        }
    

      

    4.新建类库服务项目ClientApiTest

    [ServiceContract]
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
        [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
        public class Class1
        {
            [WebInvoke(Method = "POST", UriTemplate = "blog/publish/micoblog", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
            public PublishMicoBlogResponse PublishMicoBlog(PublishMicoBlogRequest request)
            {
                PublishMicoBlogResponse re = new PublishMicoBlogResponse();
                return re;
            }
        }
    

      

    5.启动测试(报错,修改配置)

    http://localhost:54235/blog/blog/publish/micoblog

     6.WebHost修改配置:

     <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
      </system.serviceModel>
    

      

  • 相关阅读:
    C# 动态加载卸载 DLL
    C# 判断文件编码
    win10 uwp 如何拖动一个TextBlock的文字到另一个TextBlock
    C# TextBlock 上标
    PHP curl_getinfo函数
    PHP curl_file_create函数
    PHP curl_errno函数
    PHP curl_error函数
    PHP curl_escape函数
    PostgreSQL Schema
  • 原文地址:https://www.cnblogs.com/liuqiyun/p/9224070.html
Copyright © 2011-2022 走看看