我在C#应用程序中遇到了WCF问题。当服务器和客户端在同一台PC上时,我可以调用服务,但如果服务器和客户端在不同的PC上,我的请求会超时。 我已打开防火墙中的端口(我使用端口9998),我甚至试图关闭防火墙。 服务器的 app.config 如下所示:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="SMS_ServiceBehavior">
<serviceMetadata />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="SMS_ServiceBehavior" name="SMSapplication.SMS_Service">
<endpoint address="http://10.20.5.100:9998/SMS_Service" binding="basicHttpBinding"
bindingConfiguration="" name="SMS_ServiceEndpoint" contract="SMSapplication.ISMS_Service" />
<endpoint address="http://10.20.5.100:9998/mex" binding="mexHttpBinding"
bindingConfiguration="" name="mex" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
</configuration>
有没有人请知道我还能尝试什么或错误可能在哪里?
答案 0 :(得分:0)
客户端的配置文件如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="SMS_ServiceEndpoint" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:9998/SMS_Service" binding="basicHttpBinding"
bindingConfiguration="SMS_ServiceEndpoint" contract="SMS_Service.ISMS_Service"
name="SMS_ServiceEndpoint" />
</client>
</system.serviceModel>
</configuration>
答案 1 :(得分:0)
我按照以下方式处理代码:
SMS_Service.SMS_ServiceClient client = new SMS_Service.SMS_ServiceClient();
client.Endpoint.Address = new EndpointAddress(new Uri("http://10.20.5.100:9998/SMS_Service"), client.Endpoint.Address.Identity, client.Endpoint.Address.Headers);
client.Open();
client.DoWork("test");
client.Close();