开发者

Will using MTOM for small size xml data affect performance?

I have a few services hosted on a server. One service transfers a ZIP file to the client ~2kB. Another one transmits an xml representation of a DataSet ~ 10kB. The others just transfer small amounts data ~<1kB. The file transfer service and the data set service will potentially grow in size in the future.

Will it harm anything if I just use one binding for all 3 of these services with this one binding using MTOM encoding? Is WCF/MTOM smart enough to know whe开发者_如何学Gon to optimize?


If MTOM is enabled, WCF won't use it unless the message being sent is over a certain size. So yes, you can enable it without impacting small messages. I haven't found documentation that says just what that size is.

It's worth noting that MTOM only applies to binary data (ie: byte array). If you're returning a class that gets XML serialized instead, MTOM is unlikely to help you. In my experience even returning an array of 1000 of some custom class is still sent as XML text. So for what you're returning I'm not sure you'll gain anything. Marc Gravell's answer talks about how to get around that by turning the DataSet into a byte array.


You are unlikely to notice any negative side-effects from enabling MTOM here; actually, leaving aside reservations about using DataSet on a web-service, another option here is to send the DataSet as binary (with MTOM) -by:

  • change the API to take a byte[]
  • set the DataSet's RemotingFormat to binary before serializing
  • use BinaryFormatter to serialize it to a MemoryStream
  • use MemoryStream.ToArray() to get the byte[]

Much smaller than the XML version, and MTOM can exploit it

When I looked at this recently, the binary remoting format took about 20% of the space that the xml version took, for exactly the same data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜