Anonimous type name coflict: The top XML element 'ХХХ' from namespace 'YYY' references distinct types A and B. Use XML attributes to specify another XML name. RRS feed

  • Question

  • Hello

    I have to connect to existing java web service (let's call it "legacy" because I cannot control it in any way).

    "legacy" WSDL references two xml schemas with the following definitions:

    Base one

    <xs:schema xmlns:xop="" xmlns:tns="http://my.namespace" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://my.namespace" version="1.0" xmlns:xs=""> <xs:element name="MessageData" type="tns:MessageDataType"/> <xs:element name="AppData" type="tns:AppDataType"/> <xs:element name="AppDocument" type="tns:AppDocumentType"/>

    <xs:complexType name="BaseMessageType">
          <xs:element ref="tns:MessageData" />

    <xs:complexType name="MessageDataType"> <xs:sequence> <xs:element minOccurs="0" ref="tns:AppData" /> <xs:element minOccurs="0" ref="tns:AppDocument" /> </xs:sequence> </xs:complexType> <xs:complexType name="AppDataType"> <!-- some defintions --> </xs:complexType> <xs:complexType name="AppDocumentType"> <!-- some defintions --> </xs:complexType> </xs:schema>

    And additional

    <?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:tns="http://my.namespace" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://my.namespace" xmlns:xs="">

    <xs:complexType name="MyMessageType"> <xs:sequence> <xs:element name="MessageData"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="AppData" type="tns:MyDataType" /> <xs:element minOccurs="0" ref="tns:AppDocument" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> <xs:complexType name="MyDataType"> <!-- some defintions --> </xs:complexType> </xs:schema>

    (Actual schemas are larger)

    I can successfully add Service Reference for that WSDL.

    MessageDataType class is generated for tns:MessageDataType and MyMessageTypeMessageData is generated for anonymous type MyMessageType\MessageData.

    Everything can be builded and used in code. However, when I try to execute service call, I have following exception:

    "The top XML element 'MessageData' from namespace 'http://my.namespace' references distinct types MessageDataType and MyMessageTypeMessageData . Use XML attributes to specify another XML name".

    Possibly this is because of the element MessageData, that is a global definition element in first XSD, and element with anonymous type in  MyMessageType\MessageData.

    Java client (Axis2) can successfully serialize service call.

    I have two questions:

    Is the name conflict between GTD MessageData and MyMessageType\MessageData is a violation of Xml Schema specification?

    What can be done with WCF to use that "legacy" WSDL?

    • Edited by Tmth Saturday, June 2, 2012 4:45 AM
    Saturday, June 2, 2012 4:37 AM


  • just an idea - edit the second schema and add some dummy optional sibling to the MessageData element. Possibly this will force VS to create a complex class and not a conflicting top level element.
    WCF Security, Interoperability And Performance Blog

    • Marked as answer by Yi-Lun Luo Tuesday, June 26, 2012 2:26 AM
    Sunday, June 3, 2012 10:56 AM