Dot-Net

“沒有端點在監聽……”

  • May 19, 2013

我正在嘗試執行一個簡單的 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:Wcf 服務在 Windows 7 上的 IIS 7.5 下執行。

因此,當我嘗試從 wcf 代理 (IMyContract) 呼叫方法時,出現此錯誤:

http://MyServer:8000/WS上沒有可以接受消息的端點偵聽。這通常是由不正確的地址或 SOAP 操作引起的。有關更多詳細資訊,請參閱 InnerException(如果存在)。

內部異常:

{“無法連接到遠端伺服器”}

有誰知道為什麼?

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

<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 應用程序。

引用自:https://stackoverflow.com/questions/9775667