I need to asychronously call a web service from an ASP.NET application. The aspx does not need the answer from the web service. It's just a simple notification.
I'm using the ...Async()
method from web service stub and <%@Page Async="True" %>
.
ws.HelloWorldAsync();
My problem: the web page request is waiting for the web service response.
How to solve this problem? How to avoid any resource leak when the web service is down or when there is an overload?
A Web Service proxy normally has a Begin and End method too. You could use these. The example below shows how you can call the begin method and use a callback to complete the call. The call to MakeWebServiceAsynCall would return straight away. The using statement will make sure the object is disposed safely.
void MakeWebServiceAsynCall()
{
WebServiceProxy proxy = new WebServiceProxy();
proxy.BeginHelloWorld(OnCompleted, proxy);
}
void OnCompleted(IAsyncResult result)
{
try
{
using (WebServiceProxy proxy = (WebServiceProxy)result.AsyncState)
proxy.EndHelloWorld(result);
}
catch (Exception ex)
{
// handle as required
}
}
If you need to know whether the call was successful or not you would need to wait for the result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With