2016-02-05 18 views
0

我創建了一個客戶端一個WSDL,他們將請求發送,我們將盡response.Request包含任何電話號碼或位置或兩者即至少一個是required.WHat是我能的最佳方式強制限制聽到這兒過得就像我們可以用我在MVC.I已經使用試圖WCF dataanotations,但是當我在WSDL檢查通過右鍵 - >視圖瀏覽器,我不能看到類似的minOccurs的restion = 1或範圍,我們在XSD.So中看到我的問題是我需要創建單獨的XSD和驗證請求,或者我需要添加任何dataanotations.Can身體告訴我一些簡單的步驟,我可以follow.Here是我試圖數據標註與WCF

[DataMember] 
     [Required(ErrorMessage = "Name Required")] 
     public string Phonenumber 
     { 
      get 
      { 
       return this.phonenumber; 
      } 
      set 
      { 
       this.phonenumber = value; 
      } 
     } 
     /// <remarks/> 
     /// 
     [DataMember] 
       [DataMember] 
     [Required(ErrorMessage = "Name Required")] 
     public string Location 
     { 
      get 
      { 
       return this.location; 
      } 
      set 
      { 
       this.location = value; 
      } 
     } 

和WSDL我可以看到像

<xs:element name="Phonenumber" type="xs:string" nillable="true" minOccurs="0"/> 
<xs:element name="Location" type="xs:string" nillable="true" minOccurs="0"/> 

回答

0

WCF不理解[Required]屬性(或來自數據註釋命名空間的其他屬性)。如果你想需要一個數據成員,你可以在屬性設置IsRequired屬性:

[DataMember(IsRequired = true)] 
    public string Phonenumber 
    { 
     get 
     { 
      return this.phonenumber; 
     } 
     set 
     { 
      this.phonenumber = value; 
     } 
    } 
    /// <remarks/> 
    /// 
    [DataMember(IsRequired = true)] 
    public string Location 
    { 
     get 
     { 
      return this.location; 
     } 
     set 
     { 
      this.location = value; 
     } 
    } 
+0

我聽到這樣我們就可以使用註釋就像我們在MVC.I用於希望能有像HTTP方式: //rahulrraj.blogspot.ae/2012/03/wcf-error-handling-using.html.But我不知道是如果這個可以用於場景類似情況WSDL和,給到遠程客戶端 – peter