Reputation: 17180
I'm coding web service A and calling web service B.
Once I validate the input to A I want to return a success code and then invoke B.
Ways I'm considering:
The runtime context is a Service.svc hosted by an ASP.NET web app.
How should I do this?
Update: I just want to say that the answers were all useful. I decided to mark the one that I used.
Upvotes: 2
Views: 739
Reputation: 456322
Once I validate the input to A I want to return a success code and then invoke B.
In this case you should place the work into a persistent queue (MSMQ, Azure Bus, etc), and only then return a success code. Another system (not hosted in ASP.NET; i.e., Azure worker role, Win32 service, etc) should retrieve work from the queue and invoke B.
This is the only reliable way to do it. Phil Haack has a good blog post on why it's a bad idea to do both parts in ASP.NET; it comes down to recycling. More info on recycle triggers here and here.
Upvotes: 2
Reputation: 3216
The question isn't really specific to any particular service interface. Generally, your decision depends on why you want to invoke something asynchronously:
The approach to these gets easier with each subsequent framework release > 3.5, and I trust that other answers have given you good insights into the specifics of how to kick off, move on and/or wait for asynchronous task results in c#.
Upvotes: 1
Reputation: 161773
Your second idea is a good one. Send the async part to a Windows Service. If you need the reliability, then do it using a message queue. In any case, you can use WCF to send the request to the other service.
Upvotes: 1
Reputation: 11480
This link over at Code Project should give you all the information required to create a stable Async Communication with Windows Communication Foundation.
A book with a lot of handling of this form of communication:
Hopefully that helps. I'd give you some examples but that tutorial on Code Project should provide just what you need.
Upvotes: 2