Apologies upfront if this is an elementary question. How could I initiate an external web service call in an existing WCF web service and not wait for the third party service to return a response before continuing and exiting the function to allow my web service to return a value immediately?
-
1Did you try the links in [How to make a call to my WCF service asynchronous?](http://stackoverflow.com/questions/400798/how-to-make-a-call-to-my-wcf-service-asynchronous) – Andrew Coonce Jul 25 '13 at 16:45
4 Answers
You need to make the call to the external service asynchronous. There are different options depending on which version of the framework you're on. If you're on 4.5 take a look at Async: http://msdn.microsoft.com/en-us/library/vstudio/hh156513.aspx
We're currently doing something similar - invoking a restful service asynchronously from WCF using RestSharp. Take a look at an example here: Fire and Forget from within a WCF service
When you say "return a value immediately" are you saying you want the call to the WCF service itself to be non-blocking? So it would return to the client right away? If so you need to make your WCF service contract OneWay. See: http://msdn.microsoft.com/en-us/library/ms733035.aspx however, you can't return values from OneWay services.

- 1
- 1

- 1,613
- 2
- 21
- 35
You could run an asynchronous method that will initiate the call to the 3rd party and implement a second polling method that you could use to check to see if the results have been returned and action accordingly.
We do something similar for importing files. Kick of the process and have the client poll for updates.

- 12,773
- 6
- 40
- 62
If the webservice already exists and you do not have any control over it, I usually just create a thread to handle the function call.
However, in .Net 4.5, there are 'async' web service function calls. If you have access to this feature, that would be the prefered solution

- 6,303
- 6
- 44
- 75
Assuming that you don't depend on third party result to calculate your return value.
You need to structure your webservice method as follows. it is just pseudo code.
public bool YourMethod()
{
//this will be a non-blocking call
MakeAsyncCallToThirdParty();
return true;
}

- 31,833
- 6
- 56
- 65