I have a WebMethod which return a collection of PackageItemField:
[WebMethod]
public List<PackageItemField> GetAvailablePackges()
{
... ;
}
What i get :
<ArrayOfPackageItemField xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<PackageItemField name="a">1</PackageItemField>
<PackageItemField name="b">2</PackageItemField>
</ArrayOfPackageItemField>
What i need : Personalize the root element name
<SomeThingElse>
<PackageItemField name="a">1</PackageItemField>
<PackageItemField name="b">2</PackageItemField>
</SomeThingElse>
Solution which is not suitable for me : encapsulate the collecction as property inside a new class and use the follwing attributs
public class ClassTest
{
private List<PackageItemField> coll;
[XmlArray("SomeThingElse")]
[XmlArrayItem("PackageItemField")]
public List<PackageItemField> Coll
{
get
{
return coll;
}
set
{
coll = value;
}
}
}
Why not : because i'll have a root node as ClassTest int output.
Thanks for the help
Is this more what you had in mind?
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class TestService : System.Web.Services.WebService
{
[WebMethod]
[return: XmlArray("MyArray")]
[return: XmlArrayItem("MyItem")]
public List<string> HelloWorld()
{
return new List<string>() { "Hello World" };
}
}
SOAP 1.2 response:
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<HelloWorldResponse xmlns="http://tempuri.org/">
<MyArray>
<MyItem>string</MyItem>
<MyItem>string</MyItem>
</MyArray>
</HelloWorldResponse>
</soap12:Body>
</soap12:Envelope>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With