Making [Web Method] Asynchronous using “OneWay “

By default Web methods called are synchronous like HTTP request and response architecture and rely on immediate response. But sometimes asynchronous operation might be the best suited for a particular operation. .Net Framework has good support for asynchronous operation. Simplest and easiest way to make a web method asynchronous is by using OneWay property, which we discuss in this post.

OneWay property is a part of SoapRpcMethod attribute. If we set its value to true – then client does not need to wait for the web service to finish the operation of the web method and returns immediately with Http Status code 202, which indicates that service started its operation and client does not need to come back to get the status. Example of an asynchronous web method using OneWay

[WebMethod]
[SoapRpcMethod(OneWay = true)]
public void StartLongRunningAsynchronousProcess() {
// start asynchronous process + client need not to wait for the response
}
view raw gistfile1.cs hosted with ❤ by GitHub

Return type of this type of web method should be nothing other than void. If we set the return type something else – then though it will compile – it will generate exception while it will be accessed.If we look at the WSDL for this service – we will find that there is no <output> element either in <portType> or <binding> elements of StartLongRunningAsyncronousProcess method.

We could see by looking at the <portType> element of the service:

<portType name="ServiceNameSoap">
<operation name= "StartLongRunningAsynchronousProcess">
<input message="s0: StartLongRunningAsynchronousProcessSoapIn"/>
</operation>
</portType>
view raw gistfile1.xml hosted with ❤ by GitHub
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: