Search code examples
wcfasynchronousiasyncresult

WCF Async call that return void and is OneWay


I use WCF to async communicate between 2 processes.
till now I implemented the IAsyncResult pattern, and did it by having 3 methods:
BeginOperation - client.BeginOperation, when service receive it queue the job on threadpool with delegate for Operation
Operation - run on service side
EndOperation - this is what client callback.

My question is, I want to send strings from client to service, I want the send to be async, AND I dont want to get response - just want the service to print the string.
Is this enough ? This must be Non-Blocking

    [OperationContract(IsOneWay = true)]
    void PrintString(string message);

OR i need to do as following:

    [OperationContract(IsOneWay = true, AsyncPattern=true)]
    void BeginPrintString(string message, AsyncCallback callback, object state);
    void EndPrintString(IAsyncResult asyncResult);

Solution

  • IsOneWay should be enough, but it still can block your client in specific circumstances, as well as throw errors.

    See this and this posts for more details:

    General things you should keep in mind about OneWay operations -

    O/W operations must return void. O/W operations can still yield exceptions. invoking an operation on the client channel might still throw an exception if it couldn’t transmit the call over to the service. O/W operations can still block. if the service is pumped with messages and a queue had started, calling O/W operation may block your following code.