火灾和从WCF服务中忘记 [英] Fire and Forget from within a WCF service

查看:139
本文介绍了火灾和从WCF服务中忘记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在Azure上一堆WCF REST服务。里面的一些WCF服务的调用我的HTTP请求(说要发Email /短信)给外部服务。 的HTTP请求中那些非关键的第三方服务。我不希望被挡住了我的给客户呼叫响应。需要一些指导上的图案在这种情况下被使用。这是一个火,忘记我的WCF服务中的图案。

I have a bunch of WCF REST services on Azure. Inside some of the WCF services I invoke Http requests (say to send Email / sms) to external services. The http requests to the third party services that are non-critical. I do not want that to be blocking my response to the client call. Need some guidance on the pattern to be used in this case. This is for a fire and forget pattern within my wcf service.

伪code为WCF服务

Pseudo code for the WCF service

    [WebInvoke(UriTemplate = "process", Method = "POST")]
    [OperationContract]
    public bool DoSomeProcessing(DataEntity data)
    {
        bool result = ProcessData(data);
        //I do not want this call to block
        SendSMS();            
    }

    //Call to third party
    public void SendSMS()
    {
        HttpWebRequest objWebRequest = null;
        HttpWebResponse objWebResponse = null;

        objWebRequest = (HttpWebRequest)WebRequest.Create(url);
        objWebRequest.Method = "GET";

        //I do not want to wait for this response since often the web requests takes a bit of time. 
        //objWebResponse = (HttpWebResponse)objWebRequest.GetResponse();
    }

我所有的WCF服务的实例上下文模式设置为PerCall。

All my wcf services instance context mode are set to PerCall.

InstanceContextMode = InstanceContextMode.PerCall

有一些服务,发送电子邮件和短信。我不希望这些服务来阻止,直到短信调用返回。

There are some services that send Email and SMS. I do not want these services to block until the SMS calls return.

我对文学阅读和三种方法中脱颖而出

I read up on the literature and three methods stood out


  1. 射后不理使用ThreadPool.QueueUserWorkItem - 我看到了一些限制的线程数再加上如果我所有的WCF调用都是PerCall QueueUserWorkItem将是安全的。

  1. Fire and Forget using ThreadPool.QueueUserWorkItem - I am saw some limits on the number of threads plus if all my wcf calls are PerCall would QueueUserWorkItem be safe?

有对SendSMS启用单向选择一个单独的WCF REST服务功能,反过来化妆​​S中的Web请求的外部服务(虽然这似乎是一个黑客)。

Have a separate WCF REST service with the oneway option enabled for the SendSMS function that in turn make s the web request to the external services(although this seems like a hack).

使用的BeginInvoke没有EndInvoke会

Use BeginInvoke without EndInvoke

最后,在那里,我很想念什么的Azure具体。在正确的方向任何指针将AP preciated。

Finally, is there anything Azure specific that I am missing. Any pointers in the right direction would be appreciated.

推荐答案

有一个看的单程合同的。
包装你的呼叫与显示出该属性服务的外部服务。

Have a look at One Way Contracts. Wrap your call to the external service with a service that exhibits this attribute.

这篇关于火灾和从WCF服务中忘记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆