指定WCF客户端源端口

发布于 2024-12-26 17:48:05 字数 435 浏览 1 评论 0原文

我在某个地址上发布了一个 WCF 服务,我想通过 Visual Studio 中生成的代理与其进行通信。

我希望来自代理的消息使用特定的 TCP 源端口发送,但它显然会在每次调用时分配一个随机端口。

问题是这样的:我有两台主机 A 和 B 正在运行 WCF 服务(每台主机上都相同),主机 A 在地址 AdA 和端口 PA 上启动服务,主机 B 在地址 AdB 和端口 PB 上启动服务。主机A向主机B发送消息。主机B在消息之后执行一些内部操作,然后向主机A发送消息。问题在于,当主机A调用B上的webmethod时,它发送带有随机src的TCP消息端口,并且与 A 托管服务的端口不匹配,因此不会在 A 上调用 webmethod,因为 WCF 分配的源端口与发布服务的端口不匹配。

到目前为止我一直在使用BasicHttpBinding。

我怎样才能实现这个目标?

谢谢。

I have a WCF service published on a certain address, and I want to communicate with it via a proxy generated in Visual Studio.

I want the messages from my proxy to be sent with a specific TCP source port, but it apparently assigns a random port on each call.

The problem is this: I have two hosts A and B which are running a WCF Service (the same on each host), host A has the service up on address AdA and port PA, host B on address AdB and port PB. Host A sends a message to host B. Host B performs some internal operations after the message, and then sends a message to host A. The problem is that when Host A invokes a webmethod on B, it sends a TCP message with a random src port, and one that does not match the port on which A has the service hosted, so the webmethod is not invoked on A because the source port assigned by WCF does not match the port the service is published at.

I've been using BasicHttpBinding so far.

How can I achieve this?

Thanks.

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

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

发布评论

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

评论(3

慢慢从新开始 2025-01-02 17:48:05

netPeerTcpBinding 允许您指定出站端口号。

The netPeerTcpBinding allows you to specify the outbound port number.

离线来电— 2025-01-02 17:48:05

问题是,当主机 A 调用 B 上的 webmethod 时,它会发送一个
带有随机 src 端口的 TCP 消息,以及与
A 托管服务的端口,因此 webmethod 不是
在 A 上调用,因为 WCF 分配的源端口不匹配
发布服务的端口。

没有理由仅仅因为 A 的 Web 方法收到来自另一个 Web 服务的回复就应该调用它。您必须显式调用该服务。如果您希望调用 A 以响应 A 调用 B,则服务 B 中的代码必须进行该调用。尽管如果您有两个像这样相互调用的方法,那么它只会来回调用,因此您需要一个退出条件。也许如果你提供更多关于你想要实现的目标的细节,我可以提供更多建议。

The problem is that when Host A invokes a webmethod on B, it sends a
TCP message with a random src port, and one that does not match the
port on which A has the service hosted, so the webmethod is not
invoked on A because the source port assigned by WCF does not match
the port the service is published at.

There is no reason why A's web method should be invoked just because it receives a reply from another web service. You must explicitly call to the service. If you want A to be called in a response to A calling B, then the code in service B must make that call. Although if you have two methods that call each other like that it would just be back and forth so you would need an exit condition. Perhaps if you gave more details about what you are trying to accomplish I could offer more advice.

晌融 2025-01-02 17:48:05

我认为不可能为任何类型的网络通信分配源端口,因为它必须是唯一的。

源端口是 TCP/IP 分配给源端口的下一个可用端口号。
客户。这个分配的数字就是网络地址转换的方式
方法确定将响应发回给哪个用户(请参阅 NAT)。
尽管同一个客户号码可以同时使用
数千个组织,每个 TCP/IP 网络都跟踪自己的情况
分配的号码仅在该网络内使用。的组合
端口号和 IP 地址称为“套接字”。

了解更多:http://www.answers.com/topic/port-number#ixzz1jLxPzCVe< /a>

I don't think it is possible to assign the source port for any kind of network communication, as it has to be unique.

The source port is a next-available number assigned by TCP/IP to the
client. This assigned number is how the network address translation
method determines which user to send back the responses to (see NAT).
Although that same client number may be used simultaneously within
thousands of organizations, each TCP/IP network keeps track of its own
assigned numbers for use within that network only. The combination of
port number and IP address is called a "socket."

Read more: http://www.answers.com/topic/port-number#ixzz1jLxPzCVe

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