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

aun*_*ghn 10 https wcf http 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>
Run Code Online (Sandbox Code Playgroud)

谢谢

car*_*ira 12

您需要有两个端点,一个用于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> 
Run Code Online (Sandbox Code Playgroud)

  • 感谢您的回答。但是仍然无法做到这一点。当我浏览该服务以检查该服务是否正常运行时,收到以下消息:“找不到与绑定CustomBinding的端点的方案https匹配的基址。注册的基址方案为[http]。” (2认同)