Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF to ASMX binding much slower returning large data than standard web reference

I am binding to an existing ASMX web service using a WCF service reference. I have a method that returns a DataSet object that contains a string of 500k length.

As a standard "old-school" web reference, calling this method takes around 2-3 seconds to complete. As a WCF service reference this is taking 20+ seconds to complete. This is having an impact on our systems now :(

I've tried altering the bindings to max out all the maxReceivedMessageSize and maxBytesPerRead etc, but it hasn't made any difference.

Why is the WCF reference so much slower and what can I do to fix this?

like image 476
Duncan Watts Avatar asked Jun 08 '11 11:06

Duncan Watts


1 Answers

It would seem that there are a few issues here.

  1. First, WCF services, being stateful unless otherwise configured, have to be activated on every new connection. This activation is slowed by SSL due to additional trips back and forth for authentication. As one of the questions/suggestions led to above, try to make the initial connection and then attempt to execute the method 10 times or so and measure the time it takes for subsequent calls, it should be much faster after the initial call. In fact, according to MS, WCF is more efficient in handling calls than the "old school" ASMX, but is still subject to an activation time.

  2. Next, WCF has some crazy serialization action happening in the background and does not play well with a DataSet object, because of the insane amounts of overhead and metadata that the DataSet object has. If a larger dataset MUST be used, you should change the serialization of the stream to MTOM or Binary (but that only works if your clients are also WCF/.NET based). The other option would be to not use DataSets, which is probably the best option when it comes to WCF. Here is a link to an interesting article about the speed of serializing datasets.

An additional article on why not to use DataSets.

ref:

http://msdn.microsoft.com/en-us/library/bb310550.aspx

http://blogs.microsoft.co.il/blogs/oshvartz/archive/2011/07/23/wcf-performance-using-datasets-part-2.aspx

http://www.hanselman.com/blog/ReturningDataSetsFromWebServicesIsTheSpawnOfSatanAndRepresentsAllThatIsTrulyEvilInTheWorld.aspx

like image 145
iMortalitySX Avatar answered Oct 21 '22 03:10

iMortalitySX