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-基础
    手机开发-IOS
    前端- html 和css
    jmeter接口测试-文件下载
    JDBC接口
    jmeter接口测试实例7-关联
    jmeter接口测试实例6-注册(参数化)
    jmeter接口测试实例5-文件上传
  • 原文地址:https://www.cnblogs.com/liuqiyun/p/9224070.html
Copyright © 2011-2022 走看看