WCF XmlSerializer host does not speed up first request
I am creating proxy classes for java webservice clients wsdls and xsd files with svcutil. The first call made to each proxy service class takes a very long time. I was hoping to speed this up by building the XmlSerializers assembly myself (based on the article How to improve startup time for WCF client applications with the XmlSerializer ), but when I make the first call to each service it still takes the same amount of time. Here are the steps I am following:
//generate strong name key file
sn -k Blah.snk
//generate the proxy class file
svcutil blah.wsdl blah2.wsdl blah3.wsdl ... base.xsd blah.xsd ... /UseSerializerForFaults /ser:XmlSerializer /n:*,SomeNamespace /out:Blah.cs
//compile the class into an assembly signing it with the strong name key file
csc /target:library /keyfile:Blah.snk /out:Blah.dll Blah.cs
//generate the XmlSerializer code this will give us Blah.XmlSerializers.dll.cs
svcutil /t:xmlSerializer Blah.dll
//compile the xmlserializer code into its own dll using the same key to sign it and referencing the original dll
csc /target:library /keyfile:Blah.snk /out:Blah.XmlSerializers.dll Blah.XmlSerializers.dll.cs /r:Blah.dll
Then I create a standard console application, which refers both to Blah.dll
and on Blah.XmlSerializers.dll
. Then I'll try something like:
//BlahProxy is one of the generated service proxy classes
BlahProxy p = new BlahProxy();
//this call takes 30ish seconds
p.SomeMethod();
BlahProxy p2 = new BlahProxy();
//this call takes < 1 second
p2.SomeMethod();
//BlahProx2y is one of the generated service proxy classes
BlahProxy2 p3 = new BlahProxy2();
//this call takes 30ish seconds
p3.SomeMethod();
BlahProxy2 p4 = new BlahProxy2();
//this call takes < 1 second
p4.SomeMethod();
I know the problem is not server side because I can't see the request made in Fiddler until about 29 seconds. Subsequent calls to each service take <1 second, so I was hoping the main slowdown was the .net runtime generating the xmlserializer code itself, compiling and loading the assembly. I figured this would be the reason that the first call to each service is slow and the rest are fast. Unfortunatley, I am generating the code myself, not speeding up anything. Does anyone see what I am doing wrong?
a source to share
I believe the problem is not the XML serialization, but the first time the proxy is called. The first proxy call always takes a long time because WCF has to set up a good amount of plumbing.
If you know you are going to make sequential calls to the proxy (and you have no problem with the session issue), you should create a proxy as soon as possible and call Open on it. Once you have done this, you should make the proxy calls as you see fit and only dispose of when done.
Wenlong Dong details the best practices associated with creating a proxy , which has more suggestions on how you can optimize proxy performance.
a source to share
What endpoints are you exposing your service to? Sometimes the delay is due to security handshakes. Also I can suggest you to use net.tcp protocol if it meets your application requirements, it is faster than others.
I can also suggest you get started with some work, because it always delays the first proxy call and the next calls (even other users) are faster.
Tell me if it helped.
a source to share