我在 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>
有没有人知道我还能尝试什么或错误可能在哪里?
客户端的配置文件如下所示:
<?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>
我通过以下方式在代码中小心:
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();