在c#下用 WCF編寫restful

一、添加WCF服務庫web

二、在global裏面註冊路由api

 RouteTable.Routes.Add(new ServiceRoute("api", new WebServiceHostFactory(), typeof(api.OpenApi.OpenApi)));

三、在webconfig裏面添加以下配置orm

 <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <standardEndpoints>
      <webHttpEndpoint>
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" crossDomainScriptAccessEnabled="false" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="4194304" />
      </webHttpEndpoint>
    </standardEndpoints>
    <bindings>
      <webHttpBinding>
        <binding closeTimeout="04:01:00"
             openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00"
             allowCookies="false" bypassProxyOnLocal="false"
             hostNameComparisonMode="StrongWildcard"
             maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
             maxReceivedMessageSize="2147483647">

          <readerQuotas  maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483647"
        maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
        </binding>
      </webHttpBinding>
      <!--發短信-->
      <basicHttpBinding>
        <binding name="serviceSoap" />
      </basicHttpBinding>
      <!--發短信-->
    </bindings>
    <!--發短信-->
    <client>
      <endpoint address="http://api5.nashikuai.cn/service.asmx" binding="basicHttpBinding"
          bindingConfiguration="serviceSoap" contract="smsServices.serviceSoap"
          name="serviceSoap" />
    </client>
    <!--發短信-->
  </system.serviceModel>
相關文章
相關標籤/搜索