DataContractAttribute.Namespace 屬性


取得或設定型別之資料合約的命名空間。Gets or sets the namespace for the data contract for the type.

 property System::String ^ Namespace { System::String ^ get(); void set(System::String ^ value); };
public string Namespace { get; set; }
public string? Namespace { get; set; }
member this.Namespace : string with get, set
Public Property Namespace As String



合約的命名空間。The namespace of the contract.


如果您的型別必須傳回符合特定資料合約的資料,即可使用這個屬性指定特定的命名空間。Use this property to specify a particular namespace if your type must return data that complies with a specific data contract.


若要成功傳輸資料,在用戶端和伺服器上,資料合約中的資料名稱必須相同。For the data to be successfully transmitted, the name of the data in a data contract must be the same in both the client and the server. Visual Basic 專案預設會將前置詞加入至每個檔案中定義的命名空間, (稱為「根命名空間」,並在專案) 之後命名。Visual Basic projects, by default, add a prefix to the namespace defined in each file (called the "root namespace," named after the project). 加上這個前置詞會造成相同型別有不同的用戶端和伺服器命名空間。Adding this prefix causes the client and server namespaces to be different for the same type. 解決方法是將屬性設 Namespace 為 "",或明確設定此屬性中的資料合約命名空間。The solution is to set the Namespace property to "", or to explicitly set the data contract namespace in this property.