dev-masih
dev-masih

Reputation: 4756

Empty array of object after serializing XML response

I have a xml response as a wcf soap web service like bellow:

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
   <env:Header/>
   <env:Body>
      <ws:getSubjectFieldsByNameResponse xmlns:ws="https://localhost:8443/ira/ws">
         <return xmlns:ns2="https://localhost:8443/ira/ws">
            <item>
               <subjectDnField>DN_PKIX_COMMONNAME</subjectDnField>
               <defaultValue/>
               <isRequired>true</isRequired>
               <isModifiable>true</isModifiable>
            </item>
            <item>
               <subjectDnField>DN_PKIX_SERIALNUMBER</subjectDnField>
               <defaultValue/>
               <isRequired>true</isRequired>
               <isModifiable>true</isModifiable>
            </item>
         </return>
      </ws:getSubjectFieldsByNameResponse>
   </env:Body>
</env:Envelope>  

for parsing body of this xml file i used bellow response class:

[MessageContractAttribute(WrapperName = "getSubjectFieldsByNameResponse", WrapperNamespace = "https://localhost:8443/ira/ws", IsWrapped = true)]
public partial class getSubjectFieldsByNameResponse
{

    [MessageBodyMemberAttribute(Namespace = "", Order = 0)]
    [XmlArrayItemAttribute("return", Namespace = "", Form = XmlSchemaForm.Unqualified, IsNullable = false)]
    public SubjectItem[] items;

    public getSubjectFieldsByNameResponse()
    {
    }

    public getSubjectFieldsByNameResponse(SubjectItem[] items)
    {
        this.items = items;
    }
}

[XmlTypeAttribute]
public partial class SubjectItem
{
    [XmlElementAttribute(Form = XmlSchemaForm.Unqualified, Order = 0)]
    public string subjectDnField { get; set; }

    [XmlElementAttribute(Form = XmlSchemaForm.Unqualified, Order = 1)]
    public string defaultValue { get; set; }

    [XmlElementAttribute(Form = XmlSchemaForm.Unqualified, Order=2)]
    public string value { get; set; }

    [XmlElementAttribute(Form = XmlSchemaForm.Unqualified, Order=3)]
    public bool isRequired { get; set; }

    [XmlElementAttribute(Form = XmlSchemaForm.Unqualified, Order=4)]
    public bool isModifiable { get; set; }
}  

But the final result is always an empty array of SubjectItem, I tried to change some XML attributes but no luck. what should i change in response classes to get the expected result?

Upvotes: 1

Views: 377

Answers (1)

BZ_QA
BZ_QA

Reputation: 116

In visual studio, you can simply generate c# classes from XML, by:

  • Open a .cs file in VS
  • From "Edit" menu at the top, select "Paste Special" -> "Paste XML As Classes" Paste XML As Classes

Upvotes: 2

Related Questions