[英]WCF Contract first based on xsd data types
We are creating data types as XSD definitions. 我们正在创建数据类型作为XSD定义。 These xsd files are then imported into a WebSphere Application Server. 然后将这些xsd文件导入WebSphere Application Server。
We want the WebSphere Application Server to be able to call a WCF web service using these datatypes. 我们希望WebSphere Application Server能够使用这些数据类型调用WCF Web服务。
The original xsd was as follows: 原始的xsd如下:
<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: 通过xsd.exe运行此代码将产生以下C#代码:
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 ia WCF contract it produces the following xsd: 然后,当我们在WCF合约中使用此数据类型时,它将产生以下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"/>
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. 问题与具有minoccurs = 0的可选字段有关,它们实际上是可为空的,但是xsd.exe是在.net具有可为空的类型之前创建的。
How can we ensure that the datatypes used in the WCF contract are exactly the same as those specified in the XSD? 我们如何确保WCF合同中使用的数据类型与XSD中指定的数据类型完全相同?
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) EmitDefault = false表示当其默认值(即此处为null)时将不发出
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.