2012-08-16 57 views
1

我們正在創建數據類型作爲XSD定義。然後將這些xsd文件導入到WebSphere Application Server中。首先基於xsd數據類型的WCF合同

我們希望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; 
    } 
} 
} 

當我們再使用此數據類型IA 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的可選字段有關,這些字段確實可以爲空,但在.net具有可空類型之前創建了xsd.exe。

我們如何確保WCF合約中使用的數據類型與XSD中指定的數據類型完全相同?

回答

0

聲明它是這樣的:

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

然後在某個地方使用它:

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

EmitDefault = false表示,這將不發射時,其默認值(即在此空)

+0

Thnaks的答案,不幸的是它不能解決問題,在客戶端和服務器上的合同中的feilds的名稱不匹配。 – 2012-08-17 07:22:41

+0

對不起,我回答了問題的第二部分(可爲空),但沒有發現第一部分 - 我現在編輯答案:) – Chris 2012-08-17 07:39:59