Do not use one-way if you need results.
First, if you need an answer from your method, you do not want [SoapDocumentMethod(OneWay = true)] . This attribute creates a call "fire and oblivion", which never returns a response to the boat and must return void . Instead, use a regular method call and name it async.
One or two methods?
If you use ASMX, there are two main solutions: one method with a very long timeout or two methods (like @Aaronaught suggested above ): one to start the operation and return the operation identifier, and the other to transmit the identifier and get the results (if available).
Personally, I would not recommend this two-component approach in most cases because of the additional complexity, including:
- Client and server code must be changed to support two-step calling
- ASP.NET internal objects such as
Request and Response not available when called from a background task launched using ThreadPool.QueueUserWorkItem . - throttling on a busy server becomes much more difficult if multiple threads are involved with each request.
- the server should hang on the results until the client picks them up (or you decide to throw them away), which can eat RAM if the results are large.
- you cannot pass large, intermediate results back to the client
However, in some scenarios, the approach using two methods can scale better and be more resistant to broken network connections between the client and server. If you need to pick up the results a few hours later, this should be considered. But your operations take only a few minutes, and you can guarantee that the client will remain connected, given the complexity of the adjuvant function of the 2-method, I would consider that this is the last tool that will be used only if the solution with one method does not match your needs.
In any case, the solution requires two parts. First, you need to call the method asynchronously from the client. Secondly, you need to lengthen timeouts on both the client and server. I use both below.
Call ASMX Web Services Asynchronously
To invoke an ASMX web service asynchronously from a command-line application, see this article starting on page 2. This shows how to invoke a web service asynchronously from a .NET cilent application using the new Asynchronous Event-Based Template . Note that the older .NET 1.0 approach described here , which relies on the BeginXXX / EndXXX proxy methods, is no longer recommended anymore since Visual Studio Proxy Generator does not create these methods. It is better to use an event-based template as described above.
Here is an excerpt / adaptation from the article above, so you can get an idea of ββthe code involved:
void KickOffAsyncWebServiceCall(object sender, EventArgs e) { HelloService service = new HelloService();
Increase server and client latency
To prevent timeouts, http://www.dotnetmonster.com/Uwe/Forum.aspx/asp-net-web-services/5202/Web-Method-TimeOut provides a good summary of how to configure both client and server timeouts. You did not indicate in your question if you have a server method or only a client call, so the excerpt below covers both cases:
There are two sets of settings that will affect the wait time of a call to the webservice behavior:
** ASP.NET server httpruntime server timeout on the web server, this is configured through the following element:
httpRuntime Element (ASP.NET Settings Diagram)
http://msdn2.microsoft.com/en-us/library/e1f13641.aspx
<configuration> <system.web>
<httpRuntime .............
ExecutionTimeout = "45"
............... / "> </system.web> </ configuration>
Also, make sure you set <compile debug = "false" / "> so that the timeout works correctly.
** If you are using wsdl.exe or VS IDE, add the web link generated by the proxy to call the webservice methods, there is also a timeout for the client proxy class (obtained from the SoapHttpClientProtocol class). This is the Timeout property obtained from the WebClientProtocol class:
WebClientProtocol.Timeout Properties http://msdn2.microsoft.com/en-us/library/system.web.services.protocols.webclientprotocol.timeout.aspx
Therefore, you might consider customizing these two values ββto suit your application scenario. Here the former thread also mentioned this:
http://groups.google.com/group/microsoft.public.dotnet.framework.webservices/browse_thread/thread/73548848d0544bc9/bbf6737586ca3901
Please note that I highly recommend making your timeouts long enough to cover your longest operation (plus enough buffer to be safe if things are slower), but I would not recommend disabling timeouts at all. This is usually a bad programming practice, allowing unlimited waiting times, as an erroneous client or server can permanently disable another. Instead, just do timeouts for a very long time - and make sure you register instances where your clients or servers time out, so you can detect and diagnose the problem when this happens!
Finally, to repeat the comments above: for new code, it is best to use WCF. But if you are stuck using ASMX web services, this solution should work.