我正在尝试编写一个主机/客户端样式系统,该系统使用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地址而不是localhost但它不起作用,我不知道为什么。这是我的服务库的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 :(得分:0)
也许您的防火墙或路由器阻止了通信。尝试关闭防火墙。