[英]Client not connecting when used on a different computer to the host
I am trying to write a host/client style system that uses WCF and its wsHttpBinding to get data from another machine running the host software and it is working absolutely fine when I use it on the same machine to the host but when the client is on a different machine it does not work and throws an EndpointNotFoundException: 我正在尝试编写一个主机/客户端样式的系统,该系统使用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()
I thought I had done it properly because I am using the IP address of the host in the address instead of localhost but it is not working and I don't know why. 我以为我做得正确,因为我在地址中使用主机的IP地址而不是localhost,但是它不起作用,我也不知道为什么。 Here is my App.config file for the service library:
这是我用于服务库的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>
And here is the App.config file for the client console (there is nothing in the App.config for the host console: 这是客户端控制台的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>
And the code for the client console: 以及客户端控制台的代码:
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();
What am I doing wrong/not doing so that it does not connect when the client is on another machine? 我在做什么错/没有做,以便客户端在另一台计算机上时无法连接? Is it something to do with security?
与安全有关吗? This is the part that I always get stuck on whenever trying to make WCF services so I would greatly appreciate some help.
这是我每次尝试提供WCF服务时总是会遇到的问题,因此我将不胜感激。 Thank you.
谢谢。
Maybe your firewall or router is blocking the communication. 也许您的防火墙或路由器阻止了通信。 Try turning off the firewall.
尝试关闭防火墙。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.