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 | |
} |
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> | |