【发布时间】:2013-05-13 13:45:37
【问题描述】:
我一直在试验 WCF,并将 DataContract 添加到我的服务器并更新了 ServiceContract。当 ServiceReference 首次添加到客户端时,我在同一台电脑上运行它们,所以我使用了 localhost。我现在尝试通过以太网电缆连接 2 台电脑并以这种方式更新服务参考。我已将局域网上的服务器 IP 地址设置为 192.168.10.10 。当单击服务器表单上的按钮时,将执行以下代码。
private void btnCommenceService_Click(object sender, EventArgs e)
{
host = new ServiceHost((typeof(Service)), new Uri[] { new Uri("http://localhost:9000")});
host.AddServiceEndpoint(typeof(IServices),
new WSDualHttpBinding(),
"ServerService");
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(smb);
host.Open();
txtStatus.Text = "Service is open.";
}
我已经关闭了两台电脑上的防火墙,并成功地从客户端电脑上 ping 了地址"http://192.168.10.10"。如果我在浏览器中输入,我也设法访问了一些随机网页。
在客户端,如果我点击我的解决方案并选择“添加服务引用”并输入
"http://192.168.10.10"
"http://192.168.10.10:9000"
"http://192.168.10.10:9000/ServerService"
所有这些都带有某种形式的错误,通常是以下几行:
The document at the url http://192.168.10.10:9000/ was not recognised as a known document type.
The error message for each known type may help u fix the problem:
-Report from 'XML Schema' is The document format is not recognised(the content type is 'text/html;charset=utf-8').'.
Report from DISCO Document is There was an error downloading `'http://localhost:9000/?disco'.'.`
Unable to connect to the remote server.
No connection could be made because the target machine actively refused it 127.0.0.1:9000
etc
有人知道为什么它不能在 LAN 上工作,但我可以访问和 ping 地址吗?
【问题讨论】:
-
如果您将浏览器指向:'192.168.10.10:9000/ServerService?wsdl'会发生什么
-
ive 刚刚在命令提示符下输入了 telnet 192.168.10.10 9000 并且它似乎可以工作。我假设这意味着实际项目中存在问题。我在服务器端没有 app.config。我在客户端有一个。尽管 但它完全清晰的 atm
-
您是否尝试过从服务器 ping 客户端?由于 wsDualHttpBinding 需要客户端和服务器之间的双向通信,也许您可以先尝试使用 basicHttp 或 netTcp,至少可以隔离问题。返回客户端的端口可能无法访问。
-
我将客户端 ip 设置为 192.168.10.11 但我无法从服务器 ping 它。两个防火墙都关闭了。
-
如果你不能从服务器ping客户端,wsDualHttpBinding肯定是不行的。如果您只在 LAN 上工作,我推荐 wsNetTcp - 它更易于管理且速度更快,并且它支持双向通信。接下来我会试试这个。如果您必须让 wsDualHttp 正常工作,那么是时候致电您的 IT 支持以找出服务器无法 ping 客户端的原因。