0

WCFメソッドのリターンとして次のようなac#クラスがあります。

[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>

私は何が欠けていますか?

4

2 に答える 2

0

私が正しく思い出せば、それはすべてあなたの[OperationContract]がどのように定義されているかに依存します。希望する動作を得るには、メッセージコントラクトを使用する必要がある場合があります。http://msdn.microsoft.com/en-us/library/ms730255.aspxをご覧ください

于 2012-09-20T16:06:06.867 に答える
0
// The Model Object

[Serializable]
[XmlRoot("OutputItem")]
[DataContractAttribute]
public class MyObject
{
    [XmlElement("ItemName")]
    [DataMemberAttribute] 
    public string Name { get; set; }

    [XmlArray("DummyItems")]
    [XmlArrayItem("DummyItem", typeof(MyItemField))]
    public List<Fields> DummyItem { get; set; }
}



// The Class that implement the contract
[DataContract]
public class ConsumptionService : IAnyContract
{
    public MyObject GetItemXML(string id)
    {
       MyObject mo = new MyObject();
       //do some stuff to populate mi
       MyObject mo;   
    }
 }
于 2012-09-20T20:40:35.210 に答える