I have a bunch of WCF REST services on Azure. In some WCF services, I call Http requests (e.g. send emails / sms) to external services. HTTP requests to third-party services that are not critical . I do not want this to block my response to a client call. You need to be guided by the template that will be used in this case. This is for fire and forget the pattern in my wcf service.
Pseudocode for 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(); }
The entire context mode of the wcf service instance is configured on PerCall.
InstanceContextMode = InstanceContextMode.PerCall
There are several services that send email and SMS. I do not want these services to be blocked until the SMS requests are returned.
I read the literature and developed three methods
Fire and Forget with ThreadPool.QueueUserWorkItem - Have I seen some restrictions on the number of threads plus if all my wcf PerCall calls are safe in QueueUserWorkItem?
You have a separate WCF REST service with the oneway option enabled for the SendSMS function, which in turn makes a web request to external services (although this seems like a hack).
Use BeginInvoke without EndInvoke
Finally, is there anything Azure that I am missing. Any pointers in the right direction would be appreciated.
source share