2011-01-10 45 views
13

我已经创建并测试了WCF服务,一切正常。https环境下的WCF服务

当我部署到测试环境,并试图打开https://my.site/myapp/EnrollmentService.svc我已经得到了错误信息:

找不到的基址,对于端点 与结合 MetadataExchangeHttpBinding 比赛计划http。 注册基地址方案是 [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服务有什么区别?

回答

19

如果只想通过HTTPS公开您的服务(网站根本不支持HTTP),则不能使用任何依赖于HTTP的内容。你当前的配置暴露了HTTP上的帮助页面,还有mex在HTTP上引发了错误的契约。所以试试这个:

<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

通过允许HTTP解决这个问题,你需要添加一个HTTP在IIS绑定:

  1. 浏览到您的网站在IIS
  2. 点击“绑定...”在操作面板上正确的。
  3. 点击'添加'
  4. 选择'http'并确定。

或者,您也可以通过防止问题删除线,或改变:

<serviceMetadata httpGetEnabled="True"/> 

到:

<serviceMetadata httpsGetEnabled="True"/> 
+0

非常好!非常感谢! – Budda 2011-01-10 22:12:10

+0

......但是......在改变之后,网站开始在通常的“http”下工作,这是不允许的...... – Budda 2011-01-10 22:29:03

5

你已经得到HTTP元数据终结应改变为https如下。

<serviceMetadata httpsGetEnabled="True"/> 

此外,如果不是必要的,您应该从生产中移除mex和https元数据端点作为最佳实践。

+1

我是否正确地理解,我需要添加到““?这样我就可以删除该案例http绑定?如果添加此属性和删除绑定‘serviceMetadata’我已经收到了同样的错误消息..请指教 – Budda 2011-01-10 22:18:47