简体   繁体   English

在WCF可靠请求回复服务方法中进行回复时,如何处理失败

[英]How can I handle a failure when replying in a WCF reliable request reply service method

In reliable request reply I understand that the reply is acknowledged and reliable. 在可靠的请求回复中,我理解回复是公认的,可靠的。 If for some reason the reply message continually fails on all 8 attempts (the default number of retries being 8) then the channel will then be faulted. 如果由于某种原因,答复消息在所有8次尝试(默认重试次数为8)上连续失败,则该频道将出现故障。

In the server side service method, I need to take action if the reply fails, but I cannot see how I can achieve this as the service method is unaware of the WCF context. 在服务器端服务方法中,如果回复失败,我需要采取行动,但我无法看到如何实现这一点,因为服务方法不知道WCF上下文。

    /// <summary>
    /// This is my service method, and does the reply in reliable request reply
    /// </summary>
    /// <returns></returns>
    public IModelJob GetNextJob()
    {
        //dequeue the next item if there is any
        var modelJob = _priorityQueue.Dequeue();

        //if all attempts to reply fail (or at least fail to be acknowledged) then when and how do I get a chance to requeue this job?
        return modelJob;

    }

It seems much easier to handle failure when you are the client and calling a service method on the proxy itself, as you can implement your own proxy from ClientBase. 当您是客户端并在代理本身上调用服务方法时,似乎更容易处理失败,因为您可以从ClientBase实现自己的代理。

I've read: http://msdn.microsoft.com/en-us/library/aa480191.aspx , and searched about but can find nothing specific. 我读过: http//msdn.microsoft.com/en-us/library/aa480191.aspx ,并搜索过但却找不到具体内容。

Think of it in terms of the business operation you are ultimately supporting. 根据您最终支持的业务运营来考虑它。 If, for example, the service expects a sequence of messages from the client at regular 30 minute intervals, they you may have a requirement (in the business sense) that if a message is not seen for 120 minutes, then the service should notify the administrator. 例如,如果服务期望从客户端以30分钟的间隔定期发送一系列消息,那么您可能需要(在商业意义上)如果在120​​分钟内未看到消息,则服务应通知管理员。 This would be implemented in the business logic that drives your service. 这将在驱动您的服务的业务逻辑中实现。

It is not a shortcoming of WCF that you cannot have it throw an exception when it hasn't received a message - how would it know it was supposed to expect one in the first place? WCF的一个缺点是,当它没有收到消息时你不能让它抛出异常 - 它怎么会知道它应该首先期待一个?

Bear in mind that Reliable Messaging works at a layer below the application, just as TCP retransmissions take place without your HTTP application being aware at all. 请记住,Reliable Messaging在应用程序下面的层上工作,就像在没有HTTP应用程序完全了解的情况下进行TCP重新传输一样。 The fact that at the TCP level there needed to be a retransmission, or several, is not a concern of the recipient, and certainly does not throw exceptions up the protocol stack. 事实上,在TCP级别需要重传或几次重传,这不是接收者的关注,并且当然不会在协议栈上引发异常。 Its up to the sender of the data to ultimately detect that the data could not be sent, and do something about it. 它取决于数据的发送者,以最终检测到数据无法发送,并对其采取一些措施。 Or, in the example I gave, for the business logic behind the service to implement the requirement at a business level. 或者,在我给出的示例中,针对服务背后的业务逻辑,以在业务级别实现需求。

You may be interested in a blog post I wrote about some of the shortcomings of WS-ReliableMessaging. 您可能对我撰写的关于WS-ReliableMessaging的一些缺点的博客文章感兴趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何调用wcf服务方法? - How can I call the wcf service method? 在WCF REST服务POST方法中处理Json请求数据 - Handle Json Request data in WCF REST Service POST method 当服务为ConcurencyMode.Single时,如何制作单个WCF方法ConcurrencyMode.Multiple - How can I make a single WCF method ConcurrencyMode.Multiple when service is ConcurencyMode.Single 从动态crm 2011回复时如何将回复电子邮件地址更改为队列的电子邮件地址? - How to change the reply email address to the queue's email address when replying from dynamic crm 2011? WCF Ajax服务-如何将数组或JSON传递给服务? 方法参数类型应该是什么? - WCF Ajax service - How can I pass an Array or JSON to the service? What should the method parameter type be? 我如何创建wcf服务,以便在调用时接受肥皂请求 - how do i create a wcf service so that it accepts a soap request when called WCF Web服务-如何在应用程序内部查看XML请求和响应? - WCF web service - how can I view XML request and response inside my app? 当我尝试将图像作为字节发送时,WCF服务错误请求 - WCF Service Bad request when I try to send image as byte[] 如何将XmlDocument发送到WCF服务? - How can I send an XmlDocument to WCF service? 如何使用WSAddressing连接到服务WCF? - How can I connect to a service WCF with WSAddressing?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM