1

XSD定義としてデータ型を作成しています。これらの xsd ファイルは、WebSphere Application Server にインポートされます。

これらのデータ型を使用して、WebSphere Application Server が WCF Web サービスを呼び出せるようにしたいと考えています。

元の xsd は次のとおりです。

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

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

これを 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;
    }
}
}

次に、このデータ型を 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"/>
  • データ コントラクトを元の xsd と同じにしたいと考えています。
  • また、生成後にファイルを編集する必要がないようにしたいと考えています。(データモデルが大きい)

この問題は、minoccurs=0 を持つオプション フィールドに関連しています。これらは実際には null 可能ですが、xsd.exe は .net が null 可能な型を持つ前に作成されました。

WCF コントラクトで使用されるデータ型が XSD で指定されたものとまったく同じであることをどのように確認できますか?

4

1 に答える 1

0

次のように宣言します。

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

次に、どこかで使用します。

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

EmitDefault=false は、デフォルトの場合に発行されないことを意味します (つまり、ここでは null)

于 2012-08-16T12:35:45.010 に答える