【问题标题】:WCF with custombinding on both http and https在 http 和 https 上具有自定义绑定的 WCF
【发布时间】:2011-09-05 23:00:36
【问题描述】:

我有一个带有自定义绑定的 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 添加另一个端点将解决您的问题。
  • 我已添加作为答案,但仍然收到类似这样的错误“找不到与具有绑定 CustomBinding 的端点的方案 https 匹配的基地址。注册的基地址方案是 [http]。 "
  • 您需要在端点中提供两个不同的地址,因为两个端点不能共享相同的地址。
  • 你能解决它吗?如果是的话,你能发布答案吗?
  • 端点中两个不同地址的示例?

标签: wcf http https custom-binding


【解决方案1】:

您需要有两个端点,一个用于 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> 

【讨论】:

  • 感谢您的回答。但仍然无法做到这一点。当我浏览服务以检查它是否正常工作时,我收到此消息“找不到与具有绑定 CustomBinding 的端点的方案 https 匹配的基地址。注册的基地址方案是 [http]。”
  • IIS 中是否启用了 HTTPS?如果您删除 customBindingHTTP 的端点,它仍然有效吗?
  • 是的,如果我删除它就可以工作。根据您的回答,我还有一个疑问。如果网站不是 http 或 https 的映射,那时我们不能将两者都放在配置文件中。不是吗?因为服务器好像不是http映射的,只能用https浏览。
猜你喜欢
  • 2015-10-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-16
  • 2010-11-29
  • 1970-01-01
  • 2011-04-02
相关资源
最近更新 更多