gpt4 book ai didi

c# - 添加对 WCF 的服务引用(失败)

转载 作者:太空宇宙 更新时间:2023-11-03 11:04:13 25 4
gpt4 key购买 nike

我一直在试验 WCF 并将一个 DataContract 添加到我的服务器并更新了一个 ServiceContract。当第一次将 ServiceReference 添加到客户端时,我在同一台电脑上运行它们,所以我使用了 localhost。我现在尝试通过以太网电缆连接 2 台电脑并以这种方式更新服务引用。我已经将 LAN 上的服务器 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 地址吗?

最佳答案

尝试像这样更改您的绑定(bind)安全配置

WSDualHttpBinding wsDualBinding= new WSDualHttpBinding();
wsDualBinding.Security.Mode = WSDualHttpSecurityMode.None;
wsDualBinding.Security.Message.ClientCredentialType = MessageCredentialType.None;

然后添加服务端点

host.AddServiceEndpoint(typeof(IServices),wsDualBinding,"ServerService");

希望有用

关于c# - 添加对 WCF 的服务引用(失败),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16523671/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com