1

We are creating data types as XSD definitions. These xsd files are then imported into a WebSphere Application Server.

We want the WebSphere Application Server to be able to call a WCF web service using these datatypes.

The original xsd was as follows:

    <xs:simpleType name="Stillingsprosent">
         <xs:restriction base="xs:double"/>
    </xs:simpleType>

    <xs:element name="gjennomsnittStillingsprosent" type="Stillingsprosent" minOccurs="0" maxOccurs="1"/>

Running this through xsd.exe produces the following C# code:

public partial class GjennomsnittStillingsprosent {

private double gjennomsnittField;

private bool gjennomsnittFieldSpecified;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public double gjennomsnitt {
    get {
        return this.gjennomsnittField;
    }
    set {
        this.gjennomsnittField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool gjennomsnittSpecified {
    get {
        return this.gjennomsnittFieldSpecified;
    }
    set {
        this.gjennomsnittFieldSpecified = value;
    }
}
}

When we then use this datatype i a WCF contract it produces the following xsd:

<xs:complexType name="GjennomsnittStillingsprosent">
 <xs:sequence>
  <xs:element name="gjennomsnittField" type="xs:double"/>
  <xs:element name="gjennomsnittFieldSpecified" type="xs:boolean"/>
 </xs:sequence>
</xs:complexType>
<xs:element name="GjennomsnittStillingsprosent" nillable="true" type="tns:GjennomsnittStillingsprosent"/>
  • We would like the data contract to be the same as the original xsd.
  • We would also like not to need to edit the files after generation. (the data model is large)

The problem is related to optional fields that have minoccurs=0, these are really nullable, but xsd.exe was created before .net had nullable types.

How can we ensure that the datatypes used in the WCF contract are exactly the same as those specified in the XSD?

Shiraz Bhaiji
  • 64,065
  • 34
  • 143
  • 252

1 Answers1

0

Declare it something like this:

[DataContract]
public class Stillingsprosent{
[DataMember]
public double stillingsprosent;
}

Then to use it somewhere:

[DataMember(EmitDefault=false)]
public Stillingsprosent? gjennomsnittStillingsprosent;

EmitDefault=false means that it will not be emitted when its the default (ie null here)

Chris
  • 2,471
  • 25
  • 36
  • Thnaks for the answer, unfortunatly it does not fix the problem, the names of the feilds in the contract on the client and server do not match. – Shiraz Bhaiji Aug 17 '12 at 07:22
  • Sorry, I answered the second part of the question (nullable) and didnt spot the first - I'll edit the answer now :) – Chris Aug 17 '12 at 07:39