开发者

WCF performance improvements

I am developing a WPF application that talks to a server via WCF services o开发者_如何学编程ver 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜