c# - 了解 WCF 可靠 session 重试行为

标签 c# wcf ws-reliablemessaging

我有几个关于 WCF 可靠 session 可靠性的问题:

  1. WCF 是否在重试期间重新序列化消息?

    <罢工>2。如果 1 是正确的 - 它是否在消息参数被处理后发生?
    3. 如果 2 是正确的 - 是否有任何方法可以确定消息已发送?

我还无法通过反射器解决这个问题。

UPD 1:我对服务器返回值更感兴趣。他们会怎样?

更新 2: 什么时候处理消息参数(准确地说是服务器回复)?当收到适当的确认时会发生吗? 这是我所说的处理参数的意思:

at MyNamespace.MyReply.Dispose()
   at System.ServiceModel.Dispatcher.MessageRpc.DisposeParametersCore()
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessageCleanup(MessageRpc&amp;amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp;amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&amp;amp; rpc)
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
   at System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(RequestContext request, Boolean cleanThread, OperationContext currentOperationContext)
   at System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext)
   at System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult result)
   at System.ServiceModel.Diagnostics.Utility.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
   at System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously)
   at System.ServiceModel.Diagnostics.Utility.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
   at System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously)
   at System.ServiceModel.Channels.InputQueue`1.AsyncQueueReader.Set(Item item)
   at System.ServiceModel.Channels.InputQueue`1.Dispatch()
   at System.ServiceModel.Channels.InputQueueChannel`1.Dispatch()
   at System.ServiceModel.Channels.ReliableReplySessionChannel.ProcessSequencedMessage(RequestContext context, String action, WsrmSequencedMessageInfo info)
...stack continues

我需要用它来处理服务器回复(我有另一个 SOF 线程来说明我为什么使用这个解决方案)。

UPD 3:我试图解决的问题是,似乎我的服务器回复首先被处理,然后应用程序尝试序列化它。我 99% 确定我不会在其他任何地方重复使用相同的对象。 Stacktraces 非常难看,而且很大,无法在此处发布。

最佳答案

不,WCF 不会重新序列化消息。

发生的事情是这样的(简化):在 session 期间,从客户端发送的每条消息都在客户端上进行缓冲。默认情况下,有 32 条消息的空间(这可以调整;服务端也有一个缓冲区)。

然后消息被发送到服务器,如果它顺利到达并被发送,服务器发送确认,客户端从缓冲区中删除消息。

但是,如果客户端发送了消息#15 和#16,然后得到了#16 的确认(但不是#15),那么消息#15 将从缓冲区重新发送。

您可以配置很多选项,例如您是否需要按顺序发送、客户端应重试发送消息的次数等等。

查看这些文章和博客文章以获取更多信息:

希望这有助于澄清一些事情

回复更新:摘 self 引用的第一篇文章(在 MSDN 上):

If we assume having a Request/Response communication pattern, the response needs to be delivered just as reliably as the request and therefore the responding party must implement an initiator mechanism that is very similar to what the requesting party implements for the original requests. The requesting party, in turn, is playing the acceptor role for the responses. If responses get lost, they must be resent by the responding party and therefore they must also be cached (and acknowledged). Both ends of a reliable messaging session therefore maintain separate caches for outbound and inbound messages.

所以是的,这同样适用于响应,只要我们通过 NetTCP 或 HTTP 进行双向通信,它就可以正常工作 - 如文章中所述,如果单向操作 - 有关详细信息,请参阅文章。

马克

关于c# - 了解 WCF 可靠 session 重试行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1531304/

相关文章:

c# - 按字符串修剪字符串

c# - 支持小数的大数

WCF RIA 服务和 session 外的持久/静态变量

wcf - 无法加载文件或程序集“Microsoft.Practices.EnterpriseLibrary.ExceptionHandling”

java - spring-ws WS-ReliableMessaging 支持

c# - 格式化字符串以显示自定义十进制值

c# - 具有异步方法的 Getter 属性未完成执行

WCF 排队请求

c# - WCF 'one way' 通信实际上是 UDP 吗?

java - 具有可靠消息传递的 Apache CXF3.0.4 Soap Web 服务抛出异常