https环境下的WCF服务

时间:2011-01-10 21:50:47

标签: https wcf

我已经创建并测试了WCF服务,一切正常。

当我部署到TEST环境并尝试打开https://my.site/myapp/EnrollmentService.svc时,我收到了错误消息:

  

无法找到该基地址   匹配端点的方案http   有约束力   MetadataExchangeHttpBinding。   注册的基地址方案是   [HTTPS]。

互联网告诉我,我需要添加更多配置选项:

http://www.codeproject.com/KB/WCF/7stepsWCF.aspx

我添加了一些设置来维护web.config文件。现在它看起来像以下方式:

<system.serviceModel>
<services>
  <service name="McActivationApp.EnrollmentService" behaviorConfiguration="McActivationApp.EnrollmentServicBehavior">
    <endpoint 
      address="https://my.site/myapp/EnrollmentService.svc"
      binding="basicHttpBinding"
      bindingConfiguration="TransportSecurity"
      contract="McActivationApp.IEnrollmentService"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="McActivationApp.IEnrollmentService" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="McActivationApp.EnrollmentServicBehavior">
      <serviceMetadata httpGetEnabled="True"/>
      <serviceDebug includeExceptionDetailInFaults="False" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
  <basicHttpBinding>
    <binding name="TransportSecurity">
      <security mode="Transport">
        <transport clientCredentialType="None" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>

实际上,我添加了“绑定”部分并为我的端点指定了它。

但这没有改变......

请告知我需要做什么。非常感谢!

P.S。从https和http资源中消耗WCF服务有什么不同吗?

3 个答案:

答案 0 :(得分:20)

如果只想通过HTTPS公开服务(网站根本不支持HTTP),则不能使用依赖于HTTP的任何内容。您当前的配置公开HTTP上的帮助页面以及HTTP上的mex endpoing(错误的合同)。所以试试这个:

<system.serviceModel> 
  <services>   
    <service name="McActivationApp.EnrollmentService" behaviorConfiguration="McActivationApp.EnrollmentServicBehavior">     
      <endpoint address="" binding="basicHttpBinding" bindingConfiguration="TransportSecurity" contract="McActivationApp.IEnrollmentService"/>     
      <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />   
    </service> 
  </services> 
  <behaviors>   
    <serviceBehaviors>     
      <behavior name="McActivationApp.EnrollmentServicBehavior">         
        <serviceMetadata httpsGetEnabled="True"/>       
        <serviceDebug includeExceptionDetailInFaults="False" />     
      </behavior>   
    </serviceBehaviors> 
  </behaviors> 
  <bindings>   
    <basicHttpBinding>     
      <binding name="TransportSecurity">       
        <security mode="Transport">         
          <transport clientCredentialType="None" />       
        </security>     
      </binding>   
    </basicHttpBinding> 
  </bindings> 
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />      
</system.serviceModel>

答案 1 :(得分:5)

您的http元数据端点应该更改为https,如下所示。

<serviceMetadata httpsGetEnabled="True"/>  

如果没有必要,您应该从生产中删除mex和https元数据端点作为最佳实践。

答案 2 :(得分:1)

要通过允许HTTP来解决问题,您需要在IIS中添加http绑定:

  1. 导航到IIS中的站点
  2. 点击右侧“动作”面板中的“绑定...”。
  3. 点击“添加”
  4. 选择“http”然后退出。
  5. 或者,您可以通过删除行或更改:

    来防止出现此问题
    <serviceMetadata httpGetEnabled="True"/>
    

    为:

    <serviceMetadata httpsGetEnabled="True"/>