0

I'm running a Silverlight 4 application that has a WCF service reference to a service that has a lot of contracts involved.

I noticed that my startup performance was horrible so I profiled it and found that 7 seconds of time was spent generating serialization code on the first WCF call.

startup profile

I know there is a way to improve startup time by using the XmlSerializer (explained here). This is done by generating the serialization code into a separate assembly ahead of time but I can't seem to figure out how to do this in Silverlight.

Has anyone done this before? Is it even possible? Any other ideas that might help are also welcome.

Thanks.

Brandon Cuff
  • 1,438
  • 9
  • 24

2 Answers2

0

The article you linked to describes how to use svcutil.exe to pre-generate the classes, but if you're using either the "Add Service Reference" dialog box in Visual Studio or WCF RIA Services, this code generation is already done for you. So that's not where I would look for any performance boosts. And 7 seconds seems way too long for that anyway, unless you've got literally thousands of different classes that you're trying to spin up. My strong suspicion is that you've got a different problem entirely. Any operation taking seven seconds is either algorithmically or IO bound. And my bet is that this is I/O: either network I/O in reaching the WCF service, or possibly I/O from the WCF service to its own data sources. Load up a sniffer of some sort (Wireshark, Firebug, something along those lines), and get a better look at what's happening on the network. That's where I'd start, at any rate.

Ken Smith
  • 20,305
  • 15
  • 100
  • 147
  • I'm positive it's the serialization code. Running this line of code takes 7 seconds - new XmlSerializer(typeof(Request)); The Request class has about 100 XmlIncludeAttribute's defined on it. So generating serialization code for the Request class means generating code for 100 other classes. So I'm really looking for a way to use sgen.exe with Silverlight. – Brandon Cuff Jan 31 '11 at 07:39
  • Good point. Turns out I didn't know as much about serialization as I thought. But after poking around, is there a reason you're using the XmlSerializer on the WCF contract instead of the DataContractSerializer? The DCS has supposedly been optimized to avoid the XmlSerializer startup problems. – Ken Smith Jan 31 '11 at 09:15
  • Good suggestion however I tried it and I don't think it will work. The DataContractSerializer seems to have a more strict set of rules so when I attempt to generate the service reference with slsvcutil.exe /serializer:DataContractSerializer ... I get the same sort of failures as this - http://stackoverflow.com/questions/906082/problem-with-generating-webservice-proxy-using-svcutil – Brandon Cuff Jan 31 '11 at 19:41
0

It turns out that if you use the Advanced Developer Extensions you won't have the same startup performance problems as you do when you add a WCF reference.

Brandon Cuff
  • 1,438
  • 9
  • 24