2014-01-05 266 views
1

我想寫一個使用WCF和它的wsHttpBinding獲得來自另一臺機器的數據運行的主機軟件的主機/客戶的風格體系,它是工作完全正常,當我使用同一臺機器上的主機,但是當客戶端在不同的機器上它不工作,並拋出一個EndpointNotFoundException:客戶端無法連接

Unhandled Exception: System.ServiceModel.EndpointNotFoundException: There was no 
endpoint listening at http://192.168.1.64/GettingStarted/CalculatorService that 
could accept the message. This is often caused by an incorrect address or SOAP 
action. See InnerException, if present, for more details. ---> System.Net.WebExc 
eption: Unable to connect to the remote server ---> System.Net.Sockets.SocketExc 
eption: A connection attempt failed because the connected party did not properly 
respond after a period of time or established connection failed because connect 
ed host has failed to respond 192.168.1.64:80 
    at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddre 
ss socketAddress) 
    at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Sock 
et s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, 
IAsyncResult asyncResult, Exception& exception) 
--- End of inner exception stack trace --- 
    at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) 
    at System.Net.HttpWebRequest.GetRequestStream() 
    at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStre 
am() 

我以爲我已經因爲我使用的IP地址正確地完成它主機在地址而不是本地主機,但它不工作,我不知道爲什麼。下面是服務庫我App.config文件:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <appSettings> 
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> 
    </appSettings> 
    <system.web> 
    <compilation debug="true" /> 
    </system.web> 
    <system.serviceModel> 
    <services> 
     <service name="WcfServiceLibrary1.Service1"> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://192.168.1.64/Design_Time_Addresses/WcfServiceLibrary1/Service1/" /> 
       </baseAddresses> 
      </host> 
      <endpoint address="http://192.168.1.64/host" binding="wsHttpBinding" contract="WcfServiceLibrary1.IService1"> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/> 
      <serviceDebug includeExceptionDetailInFaults="False" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
</configuration> 

這裏是客戶端控制檯App.config文件(沒有什麼在App.config主機控制檯:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <startup> 
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> 
    </startup> 
    <system.serviceModel> 
     <bindings> 
      <wsHttpBinding> 
       <binding name="WSHttpBinding_IService1"> 
       <security mode="None"></security> 
       </binding> 
      </wsHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="http://192.168.1.64/GettingStarted/CalculatorService" 
       binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1" 
       contract="ServiceReference1.IService1" name="WSHttpBinding_IService1"> 
      </endpoint> 
     </client> 
    </system.serviceModel> 
</configuration> 

以及客戶端控制檯的代碼:??

ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client(); 
Console.WriteLine(proxy.InnerChannel.RemoteAddress); 
Console.WriteLine(proxy.SayHello("Henry")); 
Console.WriteLine(proxy.OsDetails());    
Console.ReadKey(true); 
proxy.Close(); 

我在做什麼錯了/不這樣做,當客戶是另一臺機器上它不連接是否是與安全這是那部分每當試圖製作WCF服務時,我都會陷入困境,所以我非常感謝一些幫助。謝謝。

+0

防火牆端口是否打開? – LueTm

+0

「(沒有什麼在App.config主機控制檯」 - 庫不使用包含在庫項目中的配置文件 - 它們使用的是使用該庫的應用程序的配置文件嘗試移動。 。''從庫的App.config到控制檯'App.config' – Tim

+0

設置我已經做到了,但它給了我在主機的錯誤: 未處理的異常信息:System.ArgumentException:此集合中已包含方案http的地址。可以有這個集合中每個方案中最多隻有一個地址。如果你的服務是在IIS osted^h 你可以通過設置「system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled」爲真或指定'解決問題system.serviceModel/serviceHostingEnvironment/baseAdd ressPrefixFilters'。 –

回答

0

也許你的防火牆或路由器阻止通信。嘗試關閉防火牆。