views:

36

answers:

3

Hello guys. I've got several web-services: asmx,wcf. At couple of them there are some methods, which take a lot of time for processing, but size of input data for these methods are small and it takes not much time to transfer on the wire. I want move to not sync model. Client passes data to service, service answers that data transfer was correct and process it at background thread witout connection with client. So agter transfering connection should be closed. IS it possible? Can u help me with articles or may be just google request.

+1  A: 

Don't do this with ASMX web services. They weren't designed for that. If you must do it with ASMX, then have the ASMX pass the data off to a Windows Service that will do the actual work, in the background.

This is more practical with WCF.

John Saunders
+2  A: 

John is right - Once you close an http connection, it is done. You can't get back to the same process.

So if you can use another technology that allows duplex on one connection (e.g. WCF), do it!

However,

if you have no choice but to use webservices,

here are three ways to make it work. You may get timeouts on any of them.

Option 1:

Forget the part about 'client answers data was correct.' Just have each thread make its request and wait for the data.

Option 2:

Now, assuming that won't work and you must do the validation, this way requires the client to make 2 requests.

First request: returns valid/invalid. Second request: returns the long-running results.

Variation of option 2:

If you have timeout problems, you could have the first request generate a GUID or unique database key and start another process, passing it this key, and return the key to the client. (if you can get the server to allow you to start a process - depends on security settings/needs - if not you may be able to start an async thread and have it keep running after the websvc one ends?) The process will do the long task, update the row in the database w/ the unique id when finished, revealing the results plus a 'done' flag. The second request by the client could always return immediately and if the processing is not done, return that, if it is, return the results. The client will repeat this every 5 sec or so until done.

Hacks, I know, but we don't always have a choice for the technology we use.

FastAl
@FastAl: when you say, "webservices", I presume you mean "ASMX web services"? WCF is "webservices" too.
John Saunders
Yes. Notably sending something using http. Although it might be possible to hack the intent of http by sending a little data, then sending some more, that would be a lot of hand-rolling. I would imagine you'd have to set WCF to communicate with something besides http? sockets, perhaps, or named pipes if the service is on the same machine? I don't know the WCF provider names by heart here but for example sockets you would leave the connection connected and just have a little chat with the server. Don't know what the ramifications of using WCF to do this are, I'm still stuck in the 00's there...
FastAl
A: 

We have been writing stuff to interact with the UK gov website and the way they handle something similar is that you send your request and data to the server and it responds saying, roughly, "thanks very much - we're processing it now, please call back later using this id" - all in an XML message. You then, at some point later, send a new http request to the service saying, essentially, "I'm enquiring about the status of this particular request id" and the server returns a result that says either it has processed OK, or processed with errors, or is still processing, please try again in xx seconds.
Similar to option 2 described previously.
It's a polling solution rather than a callback or 2 way conversation but it seems to work.

The server will need to keep, or have access to, some form of persistent table or log for each request state - it can contain eg, the id, the original request, current stage through the workflow, any error messages so far, the result (if any) etc. And the web service should probably have passed the bulk of the request off to a separate Windows service as already mentioned.

shunty