指定WCF客户端源端口
我在某个地址上发布了一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
netPeerTcpBinding 允许您指定出站端口号。
The netPeerTcpBinding allows you to specify the outbound port number.
没有理由仅仅因为 A 的 Web 方法收到来自另一个 Web 服务的回复就应该调用它。您必须显式调用该服务。如果您希望调用 A 以响应 A 调用 B,则服务 B 中的代码必须进行该调用。尽管如果您有两个像这样相互调用的方法,那么它只会来回调用,因此您需要一个退出条件。也许如果你提供更多关于你想要实现的目标的细节,我可以提供更多建议。
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.
我认为不可能为任何类型的网络通信分配源端口,因为它必须是唯一的。
了解更多: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.
Read more: http://www.answers.com/topic/port-number#ixzz1jLxPzCVe