两台 PC 之间的 WCF 通信不起作用 [英] WCF communication between two PCs doesnt work

查看:27
本文介绍了两台 PC 之间的 WCF 通信不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在两台机器之间进行 WCF 通信,其中一台充当服务器,另一台充当客户端.我能够让它在我的系统中工作,但是当我尝试连接到我朋友的系统时它不起作用.

I am trying to make a WCF communication between two machines in which one will act as server and the other will act as client. I am able to make it work within my system , but it doesnt work when i try to connect to my friend's system.

现在正在发生一件奇怪的事情.我刚刚通过提供wcftestclient 地址"从命令提示符启动了 wcftestclient.它检索了我朋友服务器的元数据.但是,当我调用该操作时,它给出错误没有端点侦听本地主机".怎么可能是本地主机?应该是我朋友的IP地址吧?

A weird thing is happening now. I just started the wcftestclient from command prompt by giving "wcftestclient address". It retrieved the metadata of my friend's server. But, when i invoke the operation, it gives error "no endpoint listening at localhost" . how can it be localhost? it should be my friend's IP address,right?

推荐答案

的一部分> 部分,而不是客户端.要更改 WCF 客户端 使用的基地址,您需要在客户端部分设置地址:

The <add baseAddress=...> is a section of the <services> section, not the client. To change the base address used by a WCF client, you need to set the address on the client section:

<client>
  <endpoint address="http://your_friend_ip/address" binding=... contract=..." />
</client>

还要注意,您可能需要在服务的防火墙中打开某个端口才能使请求通过.

Also notice that you may need to open some port in the firewall of the service to have the request go through.

另一件事,如果您朋友的服务启用了元数据,那么您可以通过指向您朋友的服务在您的机器上添加服务引用(使用 VS 添加服务引用,或使用 svcutil),这将使用适当的端点地址创建配置.

Another thing, if your friend's service has metadata enabled, then you can add a service reference on your machine (either using VS Add Service Reference, or using svcutil) by pointing to your friend's service, and that will create the config with the appropriate endpoint address.

这篇关于两台 PC 之间的 WCF 通信不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆