views:

175

answers:

1

I am developing a WPF application that talks to a server via WCF services over the internet. After profiling the application I noticed a lot of time is being taking up by creating the appropriate WCF client proxy and making the call to the server.

The code on the server is optimised and doesn't take any time to run yet I am still seeing a 1.5 second delay from when a service is invloked to it returning to the client.

A few points to give a bit of background:

  • I am using the ASP.Net membership for security
  • I will eventually hook into the same server side code through a website
  • I would eventually like to have offline support in the application

I really need to nail the performance early though as if the app is taking a couple of seconds to come back it is too long for what I am trying to do.

Can anyone suggest performance tips that will help me please?

+1  A: 

The client side proxy in WCF is basically made up of two parts. If you control both ends of the communication - e.g. if you write both the server and the client side - you can optimize this by doing the following steps:

  • isolate all service and data contracts into their own separate assembly
  • reference that assembly on both the server side (to implement your service), as well as the client side

Doing so, you don't need to create a "generic" client-side proxy by using Add Service Reference, but instead, you can take that process apart into two separate steps:

  • first step is to create a ChannelFactory<T> using your service contract, e.g.

    ChannelFactory<IMyService> factory = new ChannelFactory<IMyService>();
    

    Because you need to have access to the service contract on the client side, you need to separate those contracts out into their own assembly, so that you can reference that same contract on the client side. Creating the channel factory is the expensive part - you want to hang on to that channel factory and put it into a shared, cached container of sorts (your main form or something).

  • the second step is to create the actual channel (the "proxy") from the channel factory:

    IMyService proxy = factory.CreateChannel();
    

    This operation is much less resource intensive and can be performed before every service call and shouldn't cause much wasted time.

So with a few basic steps, you should be able to siginificantly simplify and speed up your construction of service client proxies.

marc_s
You actually don't need to reference the service contracts assembly on the client side. You could generate the proxy with `svcutil.exe` and perform the previous steps to call the service.
Darin Dimitrov