2

Few methods in my WCF service are quite time taking - Generating Reports and Sending E-mails.

According to current requirement, it is required so that Client application just submits the request and then do not wait for the whole process to complete. It will allow user to continue doing other operations in client applications instead of waiting for the whole process to finish.

I am in a doubt over which way to go:

AsyncPattern = true OR  
IsOneWay=true 

Please guide.

inutan
  • 10,558
  • 27
  • 84
  • 126

2 Answers2

3

It can be both.

Generally I see no reason for WCF operation to not be asynchronous, other than developer being lazy.


You should not compare them, because they are not comparable.

In short, AsyncPattern=True performs asynchronous invocation, regardless of whether you're returning a value or not.

OneWay works only with void methods, and puts a lock on your thread waiting for the receiver to ack it received the message.

Krzysztof Kozmic
  • 27,267
  • 12
  • 73
  • 115
  • Thank for your reply, Could you please tell what will be the advantage of AsyncPattern = true over IsOneWay=true? – inutan Feb 01 '10 at 10:59
  • Okie... well, all the service methods on which I want to implement Asynch/One way, returns void. As I understand, in IsOneWay, thread won't be locked for the whole process to complete, please correct if I am wrong. Do you suggest any good reason for me to use AsyncPattern=True here. Thank you! – inutan Feb 01 '10 at 12:13
  • IsOneWay does lock your thread. The only difference is that it does not wait for entire operation to complete on server side. It waits until server side acknowledges that it received the entire message. – Krzysztof Kozmic Feb 01 '10 at 13:11
  • I think that locking time should be minimal as I am using netTcpBinding. I was just trying to use IsOneWay on some of my service method as in http://stackoverflow.com/questions/2176701/wcf-service-setting-isonewaytrue-still-results-in-waiting-client. But it seems I am missing something, can you please suggest if I am mistaken at above link. – inutan Feb 01 '10 at 13:25
  • Perhaps it has something to do with binding you're using. WCF is a gordian knot of dependencies, it's often hard to tell what affects what. – Krzysztof Kozmic Feb 01 '10 at 13:42
0

I know this is an old post, but IMO in your scenario you should be using IsOneWay on the basis that you don't care what the server result is. Depending on whether you need to eventually notify the client (e.g. of completion or failure of the server job) then you might also need to look at changing the interface to use SessionMode=required and then using a Duplex binding.

Even if you did want to use asynchronous 2-way communication because your client DID care about the result, there are different concepts:

  • AsyncPattern=true on the Server - you would do this in order to free up server resources, e.g. if the underlying resource (?SSRS for reporting, Mail API etc) supported asynchronous operations. But this would benefit the server, not the client.
  • On the client, you can always generate your service reference proxy with "Generate Asynchronous Operations" ticked - in which case your client won't block and the callback will be used when the operation is complete.
StuartLC
  • 104,537
  • 17
  • 209
  • 285