Question

I am generating proxy classes to a clients java webservice wsdls and xsd files with svcutil. The first call made to each service proxy class takes a very long time. I was hoping to speed this up by generating the XmlSerializers assembly myself (based on the article How to: Improve the Startup Time of WCF Client Applications using the XmlSerializer), but when I do the first call to each service 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

I then create a standard Console application that references both Blah.dll and Blah.XmlSerializers.dll. I will then 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 that the problem is not server side because I don't see the request made in Fiddler until around 29 seconds. Subsequent calls to each service take < 1 second, so thats why I was hoping the main slow down was the .net runtime generating the xmlserializer code itself, compiling it and loading the assembly. I figured this would be the reason the first call to each service is slow and the rest are fast. Unfortunatley, me generating the code myself is not speeding anything up. Does anyone see what I am doing wrong?

Was it helpful?

Solution

I believe that the problem is not with XML serialization, but with the first call being made to the proxy. The first call to a proxy is always going to take a long time, because WCF has to set up a good amount of plumbing.

If you know you are going to make successive calls on the proxy (and you don't have session issue worries) then you should create the proxy as early as possible and call Open on it. Once you do that, you should make the calls to the proxy as you need them and only dispose when done.

Wenlong Dong elaborates on best practices revolving around proxy creation, which has more suggestions on how you can optimize proxy performance.

OTHER TIPS

What kind of endpoints your service expose? Sometimes the delay happens because of security handshakes. Also I can suggest you to use net.tcp protocol, if it's respond to your app requirements, it's faster than others.

I can also suggest you to start your service with some job, because it delay always doing first call to the proxy, and the following calls (even by other users) are faster.

Tell me if this helped.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top