WCF:如何通过IP:端口连接到服务

发布于 2024-09-08 17:04:32 字数 760 浏览 2 评论 0原文

我需要测试 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,但它无论如何都不起作用 - 客户端无法连接到服务。

  1. 如果我使用 wsDualHttpBinding 是否可以通过 IP 连接,如果可以,
  2. 我应该为其指定什么 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.

  1. Does it possible to connect by IP if I use wsDualHttpBinding, and if yes,
  2. What Endpoint.Address should I specify for it

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆流 2024-09-15 17:04:32

您需要指定一个类似这样的地址:

http://127.0.0.1:8000/MyService

您需要在 IP 地址和端口号之间放置一个 : - 而不是您似乎使用的 / (至少在你的帖子中)。

You need to specify an address something like this:

http://127.0.0.1:8000/MyService

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文