2012-03-19 96 views
9

我想運行一個簡單的WCF服務...「沒有終點在聽......」

我的WCF服務的.config:

<system.serviceModel> 
<services> 
    <service name ="WebService.Receptor"> 
    <endpoint 
     address = "http://MyServer:8000/WS" 
     binding = "wsHttpBinding" 
     contract = "IMyContract" 
    /> 
    </service> 
</services> 
<behaviors> 
    <serviceBehaviors> 
    <behavior> 
     <serviceDebug includeExceptionDetailInFaults="false"/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 

我的Windows服務.config:

<system.serviceModel> 
<client> 
    <endpoint 
    name = "Receptor" 
    address = "http://MyServer:8000/WS" 
    binding = "wsHttpBinding" 
    contract = "IMyContract" 
    /> 
</client> 
</system.serviceModel> 

Obs:The Wcf Serv冰IIS 7.5在Windows上運行7

所以,當我嘗試調用從WCF代理(IMyContract)的方法,我得到這個錯誤:

There was no endpoint listening at http://MyServer:8000/WS that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

內部異常:

{"Unable to connect to the remote server"}

任何人都知道爲什麼?

回答

11

當您在IIS中託管WCF服務時,您不會在地址中指定絕對URL。您應該使用.svc文件的相對網址。基礎網址將由其託管的網站決定。

<service name="WebService.Receptor"> 
    <endpoint 
     address="/WS.svc" 
     binding="wsHttpBinding" 
     contract="IMyContract" 
    /> 
</service> 

,並在客戶端上,這取決於你的IIS的配置很顯然你應該指定完整地址:

<client> 
    <endpoint 
     name="Receptor" 
     address="http://MyServer:8000/WS.svc" 
     binding="wsHttpBinding" 
     contract="IMyContract" 
    /> 
</client> 

這假定您已經配置了IIS中的網站,在8000端口上偵聽並且您已經在本網站中託管了您的WCF應用程序。