Sunday 15 January 2012

c# - Web Service Generated Code: Control serialized XML without unnecessary spaces and line breaks? -


We have a web service that uses a code gened file for messages and operation contracts generated from WSDL. There is a request to remove all formatting (freespace, indent) from serialized XML, I know about the following settings:

  settings.NewLineHandling = NewLineHandling.None; Settings.indent = false;   

Can I configure it in the web & lt; System.xml.Serialization & gt; config element? All the serials are behind the scenes, so I am thinking that I can control formatting from the configuration file because we do not say the serial method directly.

Do I have to implement custom xml serials that those settings have been implemented?

This is the answer I gave:

Exempt XML code looks justified Because your class files are auto-generated for messages, the sequence is automatically taken. You can work the code again manually to make this part, but this code is non-essential Will add complexity.

Some options:

Manually serialize.

When you call the serialization directly, there are options to stop some formatting. I do not recommend this approach because other developers will wonder why this is being done. .

Turn on HTTP Compression.

The wordpress does not matter when the message is compressed. I would also recommend this because your messages are 40-70 meg (but larger).

Use JSON

Compared to JSON, there is a much smaller size payload than for the same XML message because there are too many tags in your message Therefore, the drop of size should be important prior to the transmission.

No comments:

Post a Comment