我有这样的 ac# 类作为我的 WCF 方法的返回:
[Serializable]
[XmlRoot("OutputItem")]
public class MyItem
{
[XmlElement("ItemName")]
public string NodeName { get; set; }
[XmlArray("Fields"), XmlArrayItem(ElementName = "Field", Type = typeof(MyItemField))]
public List<MyItemField> Fields { get; set; }
}
我的 WCF 方法是这样的:
public MyItem GetItemXML(string id)
{
MyItem mi = new MyItem();
//do some stuff to populate mi
return mi;
}
我希望它的 XML 输出是这样的:
<xml version="1.0" encoding="utf-16"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<GetItemXMLResponse xmlns="http://www.here.com/XML/ItemService.xsd">
<GetItemXMLResult>
<OutputItem>
<ItemName>FR</ItemName>
<Fields>
......
</Fields>
</OutputItem>
</GetItemXMLResult>
</GetItemXMLResponse>
</s:Body>
</s:Envelope>
但是,输出如下 -<OutputItem>
顶部没有指令:
<xml version="1.0" encoding="utf-16"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<GetItemXMLResponse xmlns="http://www.here.com/XML/ItemService.xsd">
<GetItemXMLResult>
<ItemName>FR</ItemName>
<Fields>
......
</Fields>
</GetItemXMLResult>
</GetItemXMLResponse>
</s:Body>
</s:Envelope>
我错过了什么?