2014-01-17 107 views
1

我正在開發使用傳輸安全設置的WCF服務。當測試客戶端代理,並調用服務的方法,我得到以下EndpointNotFoundExceptionEndpointNotFoundException - 404 - 在IIS中通過HTTPS託管WCF服務通過Visual Studio

There was no endpoint listening at https://MyPC/AMTA.WebService/BroadcastInfoService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

Inner exception:
The remote server returned an error: (404) Not Found.

我通過Visual Studio託管我的服務。

web.config服務:

<system.serviceModel> 
    <services> 
    <service name="AMTA.WebService.Broadcasts.BroadcastInfoService"> 
    <endpoint address="/BroadcastInfoService.svc" binding="wsHttpBinding" contract="AMTA.WebService.Interface.Broadcasts.IBroadcastInfoService"/> 
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" /> 
    </service> 
</services> 
<bindings> 
    <wsHttpBinding> 
    <binding name="TransportSecurity"> 
     <security mode="Transport"> 
     <transport clientCredentialType="None"/> 
     </security> 
    </binding> 
    </wsHttpBinding> 
</bindings> 
<behaviors> 
    <serviceBehaviors> 
    <behavior> 
     <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="false"/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 

配置客戶端:

<system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
      <binding name="WSHttpBinding_IBroadcastInfoService"> 
      <security mode="Transport"> 
       <transport clientCredentialType="None"/> 
      </security> 
      </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="https://MyPC/AMTA.WebService/BroadcastInfoService.svc" 
      binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IBroadcastInfoService" 
      contract="BroadcastInfoService.IBroadcastInfoService" name="WSHttpBinding_IBroadcastInfoService"> 
     </endpoint> 
    </client> 
</system.serviceModel> 

我使用這個虛擬目錄中的項目,以本地IIS的網絡屬性頁部署:

https://MyPC:443/AMTA.WebService/ 

點擊F5後,我可以瀏覽https://MyPC:443/AMTA.WebService/BroadcastInfoService.svc,它顯示帶有w sdl信息。雖然當我嘗試致電客戶端代理方法,端點未發現異常被拋出與以下日誌細節

System.ServiceModel.EndpointNotFoundException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
The service '/AMTA.WebService/BroadcastInfoService.svc/' does not exist.
StackTrace
at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity)
at System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath, EventTraceActivity eventTraceActivity)

HTTPS和HTTP主機頭的IIS和啓用HTTPS是依賴於自簽名證書。

+0

主機和客戶端之間是否打開443?主機和客戶端在同一個盒子上嗎?試試這個:https:[no space] //127.0.0.1:443/AMTA.WebService/BroadcastInfoService.svc – Brian

+0

是的,一切都在同一臺機器上。 – Cortlendt

+0

因此,請嘗試本地主機或127.0.0.1,看看你是否得到不同的結果。 – Brian

回答

5

罪魁禍首是從端點元素缺少

bindingConfiguration="TransportSecurity"

在web.config中。

順便說一下,只需使用basicHttpsBinding(這是.NET 4.5的新增功能)即可滿足安全要求。這將導致更簡潔的XML配置。無論如何,這些都來自魔鬼。