問題描述
嚴格版本化的 WCF 服務命名空間是否應該對合同是唯一的? (Should strictly versioned WCF service namespaces be unique to the contract?)
我正在為我的 WCF 服務中的每個合同指定一個 Name
和一個 Namespace
,如 Microsoft 的 服務版本控制 指南。但是,在每個合約的示例中,Namespace
始終以 Name
值作為後綴,如下所示:
[DataContract(
Name = "PurchaseOrder",
Namespace = "http://examples.microsoft.com/WCF/2005/10/PurchaseOrder")]
public class PurchaseOrderV1 : IPurchaseOrderV1
{
[DataMember(...)]
public string OrderId {...}
[DataMember(...)]
public string CustomerId {...}
}
為什麼在 Namespace
上加上 PurchaseOrder 後綴?這不是多餘的嗎?Namespace
不應該反映整個不可變合約嗎?
如果我希望我的 DataContracts
和 ServiceContracts
一起嚴格控製版本,那麼 Namespace
值不應該是 http://examples.microsoft.com/WCF/2005/10/ ?
參考解法
方法 1:
This is natural.
http://examples.microsoft.com/WCF/2005/10/ defines a general product‑version‑like value. In the same way that you have more fine grained namespaces in your C# code, you would do the same with WCF namespaces.
At the end of the day, namespace is just a namespace and this kind of naming just a convention.
(by Aaron Daniels、Aliostad)