2012-02-16 57 views
0

以下是服務的模式。WCF模式問題

<xs:element name="StartDate" type="tns:DateType"> 
    <xs:annotation> 
    <xs:documentation>The start date of the planning item in question</xs:documentation> 
    </xs:annotation> 
</xs:element> 
<xs:complexType name="DateType"> 
    <xs:annotation> 
    <xs:documentation> 
     0 - Hard Date (Use the date defined by the year, month and day attributes 
     2 - Retirement 
     3 - Death 
     4 - Disability 
     5 - Long Term Care 
    </xs:documentation> 
    </xs:annotation> 
    <xs:sequence> 
    <xs:element name="Date"> 
     <xs:complexType> 
     <xs:attribute name="date_type" use="optional" default="0"> 
      <xs:simpleType> 
      <xs:restriction base="xs:int"> 
       <xs:enumeration value="0"> 
       <xs:annotation> 
        <xs:documentation>Hard Date (Use the date defined by the year, month and day attributes</xs:documentation> 
       </xs:annotation> 
       </xs:enumeration> 
       <xs:enumeration value="2"> 
       <xs:annotation> 
        <xs:documentation>Retirement</xs:documentation> 
       </xs:annotation> 
       </xs:enumeration> 
       <xs:enumeration value="3"> 
       <xs:annotation> 
        <xs:documentation>Death</xs:documentation> 
       </xs:annotation> 
       </xs:enumeration> 
       <xs:enumeration value="4"> 
       <xs:annotation> 
        <xs:documentation>Disability</xs:documentation> 
       </xs:annotation> 
       </xs:enumeration> 
       <xs:enumeration value="5"> 
       <xs:annotation> 
        <xs:documentation>Long Term Care</xs:documentation> 
       </xs:annotation> 
       </xs:enumeration> 
      </xs:restriction> 
      </xs:simpleType> 
     </xs:attribute> 
     </xs:complexType> 
    </xs:element> 
    </xs:sequence> 
</xs:complexType> 

這是代理類

公共部分類DateTypeDate {

private int date_typeField; 


    public DateTypeDate() 
    { 
     this.date_typeField = 0; 
    } 

    /// <remarks/> 
    [System.Xml.Serialization.XmlAttributeAttribute()] 
    [System.ComponentModel.DefaultValueAttribute(0)] 
    public int date_type 
    { 
     get 
     { 
      return this.date_typeField; 
     } 
     set 
     { 
      this.date_typeField = value; 
     } 
    } 


} 

我這裏我們需要在date_type發送0值的要求。

1-我試圖通過默認它應該分配「0」值下面。

StartDate = new DateType(); 
    DateTypeDate date = new DateTypeDate(); 

2 - 然後我明確「date_type」賦值爲0

StartDate = new DateType(); 
    DateTypeDate date = new DateTypeDate(); 
    date.date_type = 0; 
    StartDate.Date = date; 

在「date_type」節點沒有收到出現在實際的XML請求被髮送到服務這兩種情況。這是生成的請求xml。

<StartDate> 
    <Date></Date> 
    </StartDate> 

But if i assign a different value than 0 then i can see the date_type node. for example 

    <StartDate> 
    <Date date_type="2"></Date> 
    </StartDate> 


Would you able to help what could be the reason that node doesn't appear in request xml id i assign it to "0" also is there any way the node can appear without making chnages in schema. Thanks in advance 

回答

0

我不是一個XML架構專家,但在我看來,這個問題是因爲在schema中的幾行幾乎可以肯定:

<xs:attribute name="date_type" use="optional" default="0"> 

如果屬性是可選的,這意味着在客戶端不必發送它。嘗試使其成爲必需。