Sunday, June 20, 2010

How to XML serialize simple type as different element name for Generic Collection Type Argument

For web service method's parameter which is a generic collection with simple type as the type argument, the type name will be used as the XML element name in the array child node by default.

Example, if below is your web service method

[WebMethod]
public string DoWork1(List<string> partNames)


The soap message will looks like the following:


However, you can change the XML element name by specifying a XmlArrayItem attribute to the method's parameter


[WebMethod]
public string DoWork2([XmlArrayItem(ElementName = "blah")]List<string> partNames)

Labels: ,

0 Comments:

Post a Comment

<< Home