WCF在http和https上都有自定义绑定

时间:2011-06-01 03:22:49

标签: wcf http https custom-binding

我有一个带有自定义绑定的WCF服务,它在http或https上工作正常。但我完全不知道如何在http和https上提供它?

也可以这样做吗?

这是我在web.config中的配置。

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<behaviors>
    <serviceBehaviors>
        <behavior name="">
            <serviceMetadata httpsGetEnabled="true" />                    
            <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>         
    </serviceBehaviors>
</behaviors>
<bindings>
    <customBinding>                     
        <binding name="customBinding0">
          <binaryMessageEncoding />
          <httpsTransport />
        </binding>
    </customBinding>
</bindings>
<services>
    <service name="MyWCFService">                           
        <endpoint address="" binding="customBinding" bindingConfiguration="customBinding0"
            contract="MyWCFService" />
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
    </service>      
</services>

由于

1 个答案:

答案 0 :(得分:11)

您需要有两个端点,一个用于HTTP,另一个用于HTTPS。它应该工作得很好。

<bindings>
    <customBinding>
        <binding name="customBindingHTTP">
            <binaryMessageEncoding />
            <httpTransport />
        </binding>
        <binding name="customBindingHTTPS">
            <binaryMessageEncoding />
            <httpsTransport />
        </binding>
    </customBinding>
</bindings>
<services>
    <service name="MyWCFService">
        <endpoint address=""
                  binding="customBinding"
                  bindingConfiguration="customBindingHTTP"
                  contract="MyWCFService" />
        <endpoint address=""
                  binding="customBinding"
                  bindingConfiguration="customBindingHTTPS"
                  contract="MyWCFService" />
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
    </service> 
</services>