3

I want to uses XML attributes instead of elements in xmlrequest and xmlresponse, I implemented IXmlSerializable as follows:

public partial class Id : IXmlSerializable
{

    /// <remarks/>
    [XmlAttribute]
    public string lmsId;

    /// <remarks/>

    [XmlAttribute]
    public string unitId;

    /// <remarks/>

    [XmlAttribute]
    public string lmsPresId;

    /// <remarks/>

    [XmlAttribute]
    public string callId;

    public System.Xml.Schema.XmlSchema GetSchema()
    {
        return null;
    }

    public void ReadXml(System.Xml.XmlReader reader)
    {
        //implement if remote callers are going to pass your object in
    }

    public void WriteXml(System.Xml.XmlWriter writer)
    {
        writer.WriteAttributeString("lmsId", lmsId.ToString());
        writer.WriteAttributeString("unitId", unitId.ToString());
        writer.WriteAttributeString("lmsPresId", lmsPresId.ToString());
        writer.WriteAttributeString("callId", callId.ToString());
    }
}

But my service help is showing request and response as unknown


I tried even XmlSerializerFormat

[System.ServiceModel.MessageContract]
public partial class Id
{

    /// <remarks/>
    [XmlAttribute, MessageBodyMember]
    public string lmsId;

    /// <remarks/>

    [XmlAttribute, MessageBodyMember]
    public string unitId;

    /// <remarks/>

    [XmlAttribute, MessageBodyMember]
    public string lmsPresId;

    /// <remarks/>

    [XmlAttribute, MessageBodyMember]
    public string callId;
}

then I am getting everything in the xml as xmlElements instead of XmlAttributes But I am getting all the data as elements instead of Xmlattributes.

dbc
  • 104,963
  • 20
  • 228
  • 340
  • For the first case, if you want to be able to see schemas with `IXmlSerializable`, you must implement [`XmlSchemaProviderAttribute`](https://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlschemaproviderattribute%28v=vs.110%29.aspx) on your class. Then [`DataContractSerializer`](https://msdn.microsoft.com/en-us/library/ms731923%28v=vs.110%29.aspx) will pick it up. For the second case, how are you using `[XmlSerializerFormat]`? – dbc Apr 23 '15 at 22:21

0 Answers0