Mark's Stuff

My Foray Into Weblogging. Using this to store interesting items for later review.

Tuesday, December 06, 2005

.Net Asynchronous Call (Fire and Forget)

From O'Reilly's "Calling Web Services Asynchronously"

Asynchronous Call (Fire and Forget)
Very often, there can arise certain situations where a web method does not return any value. Also, a process may need to be kicked off the web server without waiting for the results. We can better illustrate this with the help of the following example. We will create an XML file using the CreateXmlFile web method, passing in a value. Note: if there is any error while creating an XML file at the web service end, then the web application cannot be notified, as the results are not returned to the web app from the web service.

// WebService web method
using System.Web.Services.Protocols;

public void CreateXMLFile(string lang) //No return value
//. . . . . . . . . . .

Client Call:

string mLangsInput = "English";

// Create an instance of the WebService
localhost.MyAsyncWebService webServ =
new localhost.MyAsyncWebService();

// Make a Web Method Call to create an XMLFile

// Do some process while the web service is processing the request

To support fire-and-forget method calls, web methods should have an attribute SoapDocumentMethod, with the OneWay attribute set to true. SoapDocumentMethod resides in the System.Web.Services.Protocols namespace; make sure that this namespace was used in the web service. Fire and forget methods cannot have any return values, as the client does not expect any results. When you use fire and forget web methods, it does not really matter whether you have chosen an asynchronous or synchronous process, as the parent thread does not wait for the results.


Post a Comment

Subscribe to Post Comments [Atom]

<< Home