发布博文
随想
读书
音乐
其他
我想爱,想吃,还想在一瞬间变成天上半明半暗的云。
我想爱,想吃,还想在一瞬间变成天上半明半暗的云。
我想爱,想吃,还想在一瞬间变成天上半明半暗的云。
我想爱,想吃,还想在一瞬间变成天上半明半暗的云。

Wcf rest https

608
高光翔
2018-10-17 20:56

https wcf rest.jpg

Wcf rest的工程在使用https协议部署后,前台调用接口会报404 (Not Found)的错误,需要修改配置文件,给服务添加绑定方式为mexHttpsBinding的终结点,并修改其它的一些配置项。下面就介绍下如何配置工程的配置文件,使wcf服务支持https协议的部署。

      首先需要给所有的服务添加绑定方式为mexHttpsBinding的终结点,在节点路径“system.serviceModel/services/service”下添加新的终结点,将bingdng属性设置为mexHttpsBinding。

      然后在节点路径“system.serviceModel/bindings/wsHttpBinding/binding”下,添加security节点,并将mode属性设置为Transport(如果存在多种绑定方式,则需对除了mexHttpsBinding的每一种都添加)。   

     最后在节点路径“system.serviceModel/behaviors/serviceBehaviors/behavior/serviceMetadata”下添加属性httpsGetEnabled="true"。

    具体的配置可参见下面的例子。

<system.serviceModel>
    <services>
   <!--车间报工服务-->
      <service name="***.***.****.****.WorkTicketReportService" 
      behaviorConfiguration="metaSupport">
        <!--webHttpBinding rest  web页面ajax可直接调用,
        或使用webClient或httpClient可直接调用-->
        <endpoint address="" contract="***.***.****.****.IWorkTicketReportService" 
        binding="webHttpBinding" bindingConfiguration="webBindingConfig">
        </endpoint>
        <!--wsHttpBinding soap协议-->
        <endpoint address="ServiceForClient" 
        contract="***.***.****.****.IWorkTicketReportService" 
        binding="wsHttpBinding" bindingConfiguration="wsBindingConfig">
        </endpoint>
        <endpoint address="mex" contract="***.***.****.****.IWorkTicketReportService"
         binding="mexHttpsBinding" >
        </endpoint>
      </service>
        </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="metaSupport">
          <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <webHttpBinding>
        <binding name="webBindingConfig">
           <security mode="Transport">
              <transport clientCredentialType="None"></transport>
           </security>
        </binding>
      </webHttpBinding>
      <wsHttpBinding>
        <binding name="wsBindingConfig">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
</system.serviceModel>

参考:https://blog.csdn.net/yenange/article/details/78224016

          https://www.cnblogs.com/mingmingruyuedlut/p/4236035.html

Insert title here Insert title here
打  赏