What is the difference between [OperationContract (IsOneWay = true)] and checking generated asynchronous operations?

What is the difference between marking a WCF method with

[OperationContract(IsOneWay = true)]

and check the box to generate asynchronous operations when adding a service link?

From what I read, it seems that the asynchronous nature of the call should only be determined on the client side. If this is the case, what is the point [OperationContract(IsOneWay = true)] ?

Right now, I only have the following method running in the WCF method.

  public void UpdateIndex(IndexElement[] indexElements) { // start the update on a new thread. Thread thread = new Thread(() => UpdateIndexThread(indexElements)); thread.Start(); } 

I created a service link in my client code, and I just call:

 indexerClient.UpdateIndex(indexElements); 

Where indexerClient is an instance of my WCF service.

Should this also work? It almost seems like he is waiting for the thread to complete before returning.

+7
wcf
source share
1 answer

It is very different.

At a conceptual level, IsOneWay = true says that the messaging pattern is “fire and forget”, unlike, for example, “response to a request”. That is, IOW = true means that there is a message from the client to the server, but not a response from the server to the client. In contrast, the non-IOW = true method will usually have a response message, even if the return type is invalid (for example, an "empty" message).

An asynchronous pattern for the behavior of the client code - for example, it blocks waiting for the return value or not. Async is a "local" thing, see this blog . You can have an asynchronous client for a synchronization server or a synchronization client for an asynchronous server. WCF will do the magic under the hood to give you either a programming model. If you have, for example, a request-response messaging template and use "generate async", the generated client will give you, for example. a method that you can call async (for example, send a message and receive a callback when a response arrives).

So, use "async" for the "local programming model" and use IOW for "messaging to wire."

Note that in your example, if you marked IOW = true, I think there is no reason for Thread.Start () in the server code. You can just do the work right there in the WCF stream provided to your server.

+11
source share

All Articles