Speed up WCF client instantiation?

180 views Asked by At

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.

0

There are 0 answers