Alex Rivera | Logout

Using WCF from WPF very slow on first use

Asked 2012-10-11T09:03:27.787
11

I have been struggling for a few days with an issue with our WPF applications and I wonder if someone has come across this before and can help? The problem seems to boil down to the client generating "on-the-fly" a serializer to handle the types in that web method call. When that method is called for the first time (the web service itself has been running already), it may take e.g. 8 seconds, subsequent calls may take e.g. 20ms. The CPU on the client WPF process is v. high during this delay.

When using the XmlSerializer, there is a way of pre-generating these serializer assemblies, using svcutil. When (as we are) using the normal WCF DataContractSerializer, this option does not seem to be present.

What I would like is to be able to pre-generate this assembly for all types in all my data contracts (a lot) or, alternatively, to replace this process with a custom one that I can code and passes the data in binary (we own both ends of this webservice/client and they are both .NET 4). I have already used BinaryForamtter and GZip compression and while this speeds up the transfer of data, it always gets restored to XML to be de-serialized by the framework, hence this problem remains.

Any ideas?

Edit
Report

1 Answer

0

You could improve the cold-start time by preloading your WCF service...i.e. don't wait for the 1st request to cause it to be loaded...load in advance.

Just a few ideas...which "might" help speed up things in the serialization area.

Regarding the pre-generation of the serialization assemblies for your service types....there is the option in Project|Build called "Generate Serialization Assembly"....if switched "On" then it generates the assemblies at Build time rather than dynamically at run time.

It's not clear if this option is only for the pre-generation of serialization assemblies for XMLSerializer based serializers, or for DataContractSerializers too. You could try switching it to "On" to see if it made a difference.

You could also try to do this early on in the code in your client and server, to exercise the DataContract serializers...i.e. before the client or server had to deal with a request...(not sure if it would help or not).

DataContractSerializer ps = new DataContractSerializer(typeof(Person));
DataContractSerializer cs = new DataContractSerializer(typeof(Company));
etc...

To make it more maintainable you could write a routine that uses reflection to locate the types that you intend to serialize e.g. look for types marked with DataContract....or some other heuritistics....or a predefined table.

answered 2012-10-11T10:00:42.230

Your Answer