查找使用 WCF net.tcp 发送消息所花费的时间

发布于 2024-07-05 19:34:20 字数 481 浏览 7 评论 0原文

我正在编写一个支持 WCF 的分布式应用程序原型,以尝试找出升级我现有的“通过 tcp 发送 xml 进行通信”应用程序时遇到的任何问题。 我正在使用回调合约向服务器注册客户端(ServiceHost 中的单例),到目前为止客户端和服务器之间的所有通信都有效。 我可以将多个客户端连接到服务器,并从服务器发送所有客户端都会收到的广播。 我可以阻止特定客户端,而其他客户端仍然会收到呼叫。 这很好。

为了继续我的学习和性能评估,我希望客户端记录服务器发送每条消息的时间,以及客户端接收同一消息的时间。 我应该如何最好地解决这个问题?

是否有类似于 SOAP 扩展的东西,我可以在其中添加从服务器的传出和到客户端的传入? 或者我是否需要向服务器在客户端调用的每个方法添加一个“timeSent”参数并记录客户端接收到的时间(哎呀!)? 有更好的方法来实现这一点吗?

我使用 net.tcp 而不是 wsDualHttpBinding (它也可以工作,但性能较差)。

I’m writing a prototype WCF enabled distributed app, to try and find out any issues I’ll have upgrading my existing “sending xml over tcp to communicate” apps I’ve got. I’m using Callback Contracts to register clients with a server (Singleton in ServiceHost) and so far all the communications between client and server work. I can connect multiple clients to the server and send a broadcast from the server that is received by all clients. I can block a particular client and the other clients still receive the calls. This is good.

To continue my learning and evaluation of performance I would like the client to record what time the server sends each message, as well as what time the client receives that same message. How should I best go about this?

Is there something similar to SOAP extensions, where I can add to the outgoing from the server and incoming to the client? Or would I need to add a “timeSent” parameter to every method that the server calls on the client and record the time received on the client (yuck!)? Is there a better way to accomplish this?

I am using net.tcp rather than wsDualHttpBinding (which also works but is less performant).

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

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

发布评论

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

评论(2

唔猫 2024-07-12 19:34:20

大卫关于时钟同步问题的看法是正确的。 然而,在 WCF 上,在服务/客户端实现之外添加时间戳信息并不困难。

你是对的,它不支持 SoapExtensions,但事实上,它具有更丰富的扩展点集。 在您的具体情况下,我认为添加 MessageInspector 的自定义行为可能会起作用。

实际上有两个消息检查器接口: 一个用于客户端 (IClientMessageInspector),还有一个用于服务器 (IDispatchMessageInspector)。

在服务端连接调度检查器的最简单方法是通过服务行为 (IServiceBehavior),因为您可以将其作为自定义属性连接到服务实现。 下面是一个简单示例,说明了如何执行此操作。 您还可以通过 IEndpointBehavior 连接它,但是您需要在设置服务主机时通过代码或通过配置来完成此操作,这需要编写更多代码。

在客户端,您仍然使用端点行为,但通过代码引入这些行为要容易得多,因为您可以从代理客户端直接访问 ClientRuntime。

无论如何,我认为像时间戳这样的东西最好作为自定义标头添加到消息中,这样它就不会直接成为消息负载的一部分。

David is right about the problems with clock synchronization. However, adding the timestamp information outside of the service/client implementation is not hard at all on WCF.

You're right it doesn't support SoapExtensions, though, in fact, it has a much richer set of extensibility point. In your specific case, I think a custom behavior that adds a MessageInspector would probably work.

There are actually two message inspector interfaces: One for the client (IClientMessageInspector), and one for the server (IDispatchMessageInspector).

The easiest way to hook up a dispatch inspector on the service side is through a service behavior (IServiceBehavior), since you can hook that up to your service implementation as a custom attribute. Here's a simple example of how to do it. You can also hook it up through an IEndpointBehavior, but you need to do that either through code when setting up the service host or through configuration, which requires writing a bit more code.

On the client side, you still use an endpoint behavior, but introducing those through code is a lot easier since you have direct access to the ClientRuntime from the proxy client.

Anyway, I would think that something like a timestamp is better added to the message as a custom header so that it is not part directly of the message payload.

风渺 2024-07-12 19:34:20

嗯...这是一个困难的问题。 这里的问题是您甚至无法确保客户端和服务器计时器同步。

如果您想做的是发送一些带外数据,这样您就不需要修改您的方法,您可以使用建议的方法 此处。 我认为应该足够了。

Hmmm... that's a difficult one. The problem here is you can't even make sure both the client and the server timers are in sync.

If what you want to do is send some out-of-band data, so that you don't need to modify your methods, you can use the method suggested here. I think it should be enough.

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