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

3

7

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?

Silvereye answered 8/6, 2011 at 11:16 Comment(3)
What is the size of the transmitted message before and after? The first thing to figure out is whether this is bandwidth related vs processing overhead (security etc). 500k is not unreasonable.Boston
Have you tried looking at the WCF tracing (for the client) and IIS logs (for the server) to see where the time is being taken? Sounds like it's at the client side, but would be good to narrow the problem area down.Viscera
Also, is the slowdown seen on every call? If you call the service 10 times in a row, is it the same performance every time?Brogle
P
2

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

Prynne answered 1/8, 2012 at 2:50 Comment(1)
Actually, the job of everyone who uses Stack Overflow is to constantly improve both the questions and the answers. Thanks for improving your answer.Brogle
L
0

You do need to look at a number of aspects, not least that you are comparing like for like in terms of data quantities. It may be that there are other factors that have caused the slow down.

My first question would be why have you changed it to WCF? Was there a specific reason for this - I know it is the right way to go but is there a specific reason that meant this needed to be changed now? Were there any changes to the interface that might have had wide ranging effects.

The WCF is liable to be slightly slower, because of the object processing, but it should not have anything like this difference. Which would all point to something else in the environment being the real issue.

Leibowitz answered 23/6, 2011 at 10:25 Comment(2)
It wasn't changed, it has always been a wcf reference, the web reference was added to test the speed as we have other applications which download the same data from the same web service without any speed issues. I'd like to add that this web service does live behind an ssl cert over https.Silvereye
OK, some of the parts of the interface will slow stuff down ( WCF and SSL ), but not significantly, unless you are processing very substantial amounts of data. This would point to an environmental change. Can you run the tests with both the new and the old-school and new-school methods, and compare times. Then I would suggest ensuring database access is the same. There is not straightforward answer, and there should not be this difference, so you will have to chase through to identify where the problem is coming from.Leibowitz
S
0

What type of binding is being used? There is the BasicHttpBinding and WSHttpBinding, and to simulate an asmx, BasicHttpBinding is recommended. In general, WCF should be at least comparable to their asmx counterpart. If that doesn't help, try tweaking the concurrency settings and instantiation modes for the WCF.

Sclera answered 10/9, 2011 at 4:19 Comment(1)
He can't bind to an existing asmx service with wsHttpBinding on a client. It is obvious that he uses basicHttpBinding.Ciliary

© 2022 - 2024 — McMap. All rights reserved.