在 http 和 https 上具有自定义绑定(bind)的 WCF

标签 wcf http https custom-binding

我有一个带有自定义绑定(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/

相关文章:

java - 如何在不继续不受信任的证书页面的情况下从 Angular2 发出 https 请求

c# - Web 服务与 Java 的集成,它们的类型有问题吗?

c# - 多个绑定(bind)的 WCF Mex 端点

http - golang http 允许带有 www 和不带 www 的特定域名

http - 如何使用 "POST to PUT redirect"建模 REST API?

ios - HTTP Post 适用于 WIFI 但不适用于 Cell

azure - 通过 ARM 模板部署在 Azure Front Door 自定义域上启用 HTTPS

c# - 没有 DataMember 属性的 DataContract 序列化

wcf - 在 Azure 上托管非 WCF 服务

http - 使用 http 或更好的 https 的项目类型?