我有一个带有自定义绑定(bind)的 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>
谢谢
最佳答案
您需要有两个端点,一个用于 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>
关于在 http 和 https 上具有自定义绑定(bind)的 WCF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6195927/