WCF:如何通过IP:端口连接到服务
我需要测试 WCF 服务,但只有一台计算机,因此我的服务和客户端运行在同一台计算机上。这是 WCF 服务的 App.config:
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/MyService"/>
</baseAddresses>
</host>
<endpoint address=""
binding="wsDualHttpBinding"
contract="MyService.IMyService"/>
我需要通过 IP 从客户端连接到此服务,因此我尝试了以下操作:
MyClient.Endpoint.Address =
new System.ServiceModel.EndpointAddress(
new Uri("http://" + IP + "/" + Port + "/MyService"));
其中 IP =“127.0.0.1”,端口 =“8000”。我还尝试使用我的真实 IP 地址而不是 127.0.0.1,但它无论如何都不起作用 - 客户端无法连接到服务。
- 如果我使用 wsDualHttpBinding 是否可以通过 IP 连接,如果可以,
- 我应该为其指定什么 Endpoint.Address
I need to test WCF service, but have only one computer, so my service and client are running on the same machine. Here is the App.config of WCF Service:
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/MyService"/>
</baseAddresses>
</host>
<endpoint address=""
binding="wsDualHttpBinding"
contract="MyService.IMyService"/>
I need to connect to this service from my client by IP, so i tried following:
MyClient.Endpoint.Address =
new System.ServiceModel.EndpointAddress(
new Uri("http://" + IP + "/" + Port + "/MyService"));
where IP = "127.0.0.1" and Port = "8000". I also tried to use my real IP address instead of 127.0.0.1 but it doesn't work anyway - client cann't connect to service.
- Does it possible to connect by IP if I use wsDualHttpBinding, and if yes,
- What Endpoint.Address should I specify for it
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要指定一个类似这样的地址:
您需要在 IP 地址和端口号之间放置一个
:
- 而不是您似乎使用的/
(至少在你的帖子中)。You need to specify an address something like this:
You need to put a
:
between the IP address and the port number - not a/
as you seem to use (at least in your post).