2011-01-10 68 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