Search code examples
wcfcommand-query-separation

WPF Client - Should I make calls to WCF service in background thread?


I have a WPF client that makes calls to 2 WCF services.

One service is for querying only and one service is for commands (CQS pattern).

How should I make the calls to the commands service ?

I read somewhere that all the operations in the command service must be 'One-Way', because they should not return any values. And that if something went wrong - the operation should throw a 'FaultException' to the client.

But if the commands are all One-Way - what do I do in the client ?

Say I have an 'AddProduct' window in the WPF client, and I enter information and press 'Save'.

I now call 'AddProduct(Product)' in the service, but :

  1. Should it close the window ?
  2. Should it wait for 10 seconds to see if there wasn't any FaultException ?
  3. Should the operation not be 'One-Way' ? If so - should all operations in the command service return some type of generic 'Result' object with 'succeeded' or 'failed' ?
  4. If section 3 is 'Yes' - should I call the service in a seperate thread and 'disable' all the controls on the window until I get a response back from the service ?

Thanks.


Solution

  • I would say option 3 is the way to go, but you probably do not need the generic Result object to communicate errors to the client. As you might know, exceptions are not serialized in the SOAP message so you won't get any of the usual .NET exceptions on the client side. On the other hand, you can still take advantage of SOAP Faults by catching FaultException on the client. Accordingly, if no exceptions were caught on the client, then everything went well.

    For more information about fault exceptions and how you can use them to your benefit, take a look at:

    Specifying and Handling Faults in Contracts and Services