XSD schema with import and DataContractSerializer

Topics: Service Factory Modeling Edition Forum
Jan 22, 2008 at 1:17 PM
I have some XSD schemas (see below) where I use import and want to add this to a XSD Message on the Service Contract Model. I receive the following error:
The global element 'urn:geoservice:komtek:orderline:Orderline has already been declared.

Is there any restrictions on the use of import in the XSD schemas on the service factory for Visual Studio 2008 and is there any workarounds so you can use the DataContractSerializer(I have understood that DataContractSerializer do not support import)? I have a contract first design.

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema targetNamespace="urn:geoservice:komtek:order" elementFormDefault="qualified" xmlns:tns="urn:geoservice:komtek:order" xmlns:mstns="urn:geoservice:komtek:order" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:orderline="urn:geoservice:komtek:orderline">
<xsd:import id="orderline" namespace="urn:geoservice:komtek:orderline" schemaLocation="OrderLine.xsd" />
<xsd:element name="Order">
<xsd:complexType>
<xsd:sequence maxOccurs="unbounded" minOccurs="0">
<xsd:element ref="orderline:OrderLine" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema targetNamespace="urn:geoservice:komtek:orderline" elementFormDefault="qualified" xmlns:tns="urn:geoservice:komtek:orderline" xmlns:mstns="urn:geoservice:komtek:orderline" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="OrderLine">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="OrderType" type="xsd:string" />
<xsd:element name="ProductNumber" type="xsd:int" />
<xsd:element name="ProductName" type="xsd:string" />
<xsd:element name="ProductCount" type="xsd:long" />
<xsd:element name="ProductUnit" type="xsd:string" />
<xsd:element name="ProductUnitPrice" type="xsd:decimal" />
<xsd:element name="Share" type="xsd:string" />
<xsd:element name="PersentCorrection" type="xsd:decimal" />
<xsd:element name="ProductStartDate" type="xsd:dateTime" />
<xsd:element name="ProductEndDate" type="xsd:dateTime" />
<xsd:element name="Price" type="xsd:decimal" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Developer
Jan 22, 2008 at 4:28 PM
You can try updating your schema to be compatible with DataContractSerializer removing the include and max,min occurs in the Order sequence.

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema targetNamespace="urn:geoservice:komtek:order" elementFormDefault="qualified" xmlns:tns="urn:geoservice:komtek:order" xmlns:mstns="urn:geoservice:komtek:order" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:orderline="urn:geoservice:komtek:orderline">
  <xsd:element name="Order">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="OrderLine">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="OrderType" type="xsd:string" />
              <xsd:element name="ProductNumber" type="xsd:int" />
              <xsd:element name="ProductName" type="xsd:string" />
              <xsd:element name="ProductCount" type="xsd:long" />
              <xsd:element name="ProductUnit" type="xsd:string" />
              <xsd:element name="ProductUnitPrice" type="xsd:decimal" />
              <xsd:element name="Share" type="xsd:string" />
              <xsd:element name="PersentCorrection" type="xsd:decimal" />
              <xsd:element name="ProductStartDate" type="xsd:dateTime" />
              <xsd:element name="ProductEndDate" type="xsd:dateTime" />
              <xsd:element name="Price" type="xsd:decimal" />
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>
If you want to use include, the you should use an XmlSerializer. The xsd picker has an issue with the serializer type (always use the DataContractSerializer) and therefore it will show that error. The workarrouind here is to open your service contract model file with an XML Editor (open with in VS) and manually update the 'element' attribute of the XsdMessage element poiting to your 'Order' type.
Jan 29, 2008 at 10:14 PM
Hi charlyfriend, can you post an example of how to update the 'element' attribute of the XSD Message? Thanks
Developer
Jan 31, 2008 at 8:10 PM
Open the sc model file with an XML editor (from VS) and look the message section:

 <messages>
    <xsdMessage Id="30010c42-adbd-433d-aa37-a18dd2073fab" name="XsdMessage1" namespace="sc:sc" objectExtenderContainer="AAEAAAD..." element="xsd://schemas\BaseTypes.xsd?ordersByCustomer" isWrapped="false">
      <requestFor>
        <operationMoniker Id="bf28ba6e-01ba-419f-9fcd-a241f91c1f6a" />
      </requestFor>
    </xsdMessage>
  </messages>
Locate the element attribute in the xsdMessage element with the name of your message element and update it to your required type. In the above sample you will change the value "xsd://schemas\BaseTypes.xsd?ordersByCustomer" in the element attribute.