1

Suppose my WCF client interface is called ISDK, and the client object itself is called ISDKClient, as generated by svcutil.

When I instantiate a WCF client like this:

Dim myClient As New ISDKClient

it takes around 1.5sec to create the first client, then ~300ms subsequently.

If I use a channel factory approach:

Dim myChannelFactory As New ChannelFactory(Of ISDK)(binding, endpoint)
Dim myChannel As ISDK = myChannelFactory.CreateChannel()

Takes 1.5sec for the first call, but subsequent calls to CreateChannel are near instant. The problem is that method signatures in ISDK are different from those listed under ISDKClient. ISDK has request/response pattern, while ISDKClient has normal methods with parameters.

Can I control how svcutil generates a proxy file, to avoid request/response method signature pattern in the interface? According to MSDN, method signatures should match, i.e. client should directly reference its interface for all calls (but it's not my case):

Public Function SampleMethod(ByVal msg As String) As String _
                                           Implements ISampleService.SampleMethod
  Return MyBase.Channel.SampleMethod(msg)
End Function 

If not, is it possible to instantiate a WCF client based using an already existing channel? Something like:

Dim myClient As New ISDKClient(myChannel)

If not, is there any other way to improve performance of instantiating new WCF clients in my application? Assuming all that's available is a WCF service over HTTP.

Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151
  • Find out where the time is being spent. – John Saunders Dec 02 '14 at 21:24
  • @JohnSaunders: Creating metadata for a channel, obviously. – Victor Zakharov Dec 02 '14 at 21:25
  • "Obviously", and, during what part of creating a channel? Is it blocked on network I/O? To where? "Obviously", it's network I/O to the service. But what if it's not? – John Saunders Dec 02 '14 at 21:31
  • @JohnSaunders: Channel factory and the client should be using the same way of accessing the resource. The only difference is that the [heavy lifting](http://msdn.microsoft.com/en-us/library/hh314046(v=vs.110).aspx) is done once. There is no network I/O going on to create a client or channel from a factory. I tested with no access to the WCF service, everything still runs, with numbers being the same. If I profile, it says "not my code" is where time is being spent, specifically the `clr.dll`. – Victor Zakharov Dec 02 '14 at 21:34

0 Answers0