XmlSerialization of object data type

hi folks,

i want .net framework to xml serialize the below class, based on the type of data present in the second data member.

but, only the first data member gets serialized and the second member is ignored.

is this the way to implement what i am looking at

that too, in .NET 1.1.

http://xxx")]
public class MessageParams
{
[XmlElement("Credentials")]
public Credential cred;

[XmlElement("FirstMethodParm", typeof(FirstMethodDataType))]
[XmlElement("ScndMethodParm",typeof(ScndMethodDataType))]
public object Item;

}
TIA
Sek


Answer this question

XmlSerialization of object data type

  • Addy77

    hi folks,

    here is additional info.

    i am trying to create a web service signature classes from wsdl file using wsdl.exe tool on .NET 1.1

    my wsdl refers a xsd for data types. following is a datatype from the xsd.

    <xs:element name="CommandMessage">
    <
    xs:complexType>

    <xs:sequence>

    <xs:element name="Authentication" type="nms:Authentication"/>

    <xs:choice>

    <xs:element name="UpdatePermission" type="nms:UpdatePermissionParams"/>

    <xs:element name="DeletePermission" type="nms:DeletePermissionParams"/>

    </xs:choice>

    </xs:sequence>

    </xs:complexType>

    </xs:element>

    when i use the wsdl.exe to generate my web service class, the above is generated as the following class:

    http://xxx")]
    public class CommandMessage
    {
    [XmlElement("Authentication")]
    public Authentication cred;

    [XmlElement("UpdatePermission", typeof(UpdatePermissionParams))]
    [XmlElement("DeletePermission",typeof(DeletePermissionParams))]
    public object Item;

    }
    the webmethod created by wsdl.exe that uses the above struct is
    /// <remarks/>
    [WebMethodAttribute()]
    [SoapDocumentMethodAttribute("urn:#UpdatePermissions", Use=Literal, ParameterStyle=Bare)]
    [return: XmlElementAttribute("MessageReceipt", Namespace="
    http://xxx")]
    public abstract MessageReceipt UpdatePermissions(CommandMessage CommandMessage);

    when the webservice is tested, the test page for the above webmethod shows the following as SOAP message format:This is NOT the expected result, as the "UpdatePermission" element is expected as a sibling of "Authentication" element.
    <soap:Body>
    <CommandMessage xmlns="
    http://xxx">
    <Authentication>
    <LoginName>string</LoginName>
    <Password>string</Password>
    <CallerUserID>string</CallerUserID>
    </Authentication>
    </CommandMessage >
    </soap:Body>

    Following is the expected result, as "UpdatePermission" is appearing as a sibling of "Authentication" element.
    <soap:Body>
    <CommandMessage xmlns="
    http://XXX">
    <Authentication>
    <LoginName>string</LoginName>
    <Password>string</Password>
    <CallerUserID>string</CallerUserID>
    </Authentication>
    <UpdatePermission>
    <Source/>
    <Destination/>
    </UpdatePermission>
    </CommandMessage >
    </soap:Body>

    The surprising thing is, the steps of conversion from xsd to classes are done using framework automated tools, but the output is not as expected.
    where am i going wrong
    any comments would be of great help.

  • SoulSolutions

    hi.

    is there any problem else

    can you post more detail.



  • kinny_k

    I answered this question on a different thread: basically you cannot use default test page as a test tool: it just sows some sample message; it does not show all members of a complex type, just the first one: it skips the optional members.

    You should use soap client and trace to test the web service. Or alternatively you can take a look at the schema definition for your messages to verify that the choice element is included (I am sure it is).

    Also you could change the code for the default test page to show more members, the code resides in an aspx page, take a look at the DefaultWsdlHelpGenerator.aspx in the config directory under the .Net Framework installation dir.

    Thanks,

    Elena Kharitidi


  • Ramaat

    hi. guy.

    i had go on a testing , it work fine.

    maybe it's a bug for .net1.1,

    in .net 2.0 ,it work fine..



  • DKB

    hi matt,

    thanks for your reply.

    any other pointers to suggest

    thks

    sek


  • kalkumar

    There should be not problems serializing this class.

    Could you post your calling code Are you initializing the Item member of the MessageParams

    Is this the full class definition, or just a snipped Does the class a boolean member called ItemSpecified

    Thanks,

    Elena Kharitidi


  • XmlSerialization of object data type