2009-10-28 69 views
5

即使在詢問之前,我仍覺得這是一個愚蠢的問題,但現在我的大腦工作得並不順利。我有兩個WCF服務「CountryService」和「FloristService」。在WCF服務之間共享DTO對象

現在CountryService有以下方法:

IList<CountryDTO> GetAllCountries(); 

此外,FloristService有一個方法:

bool AddFlorist(FloristDTO florist); 

所有好爲止,但問題是,FloristDTO引用CountryDTO即

public string Address1 { get; set; } 
    public string Address2 { get; set; } 
    public string Address3 { get; set; } 
    public string City { get; set; } 
    public string Postcode { get; set; } 
    public CountryDTO Country { get; set; } 
    public string Name { get; set; } 

這很好,但如果我使用服務代理生成實用程序ith Visual Stuidos(即添加引用「>」添加服務引用「),然後我創建了兩個版本的CountryDTO:BeingFloristService.CountryDTO和CountryService.CountryDTO。

現在我可以想出幾種方法來解決這個問題,但其中沒有一個看起來是正確的。我想知道這個「正確」的方法是什麼,我能用代理生成工具做些什麼來讓它共享通用的DTO?

乾杯,克里斯

回答

5
+0

乾杯,正是我之後 – Owen 2009-10-28 13:29:44

+0

第二個想法,這似乎假設服務層和使用層將有權訪問與DTO對象相同的.dll現在如果我沒有這個,並且我想要svutil生成代理類。但我只希望他們生成一次並在服務中共享? – Owen 2009-10-28 13:32:59

+1

然後,您只需生成一次代理類,然後通過svcutil/r將生成的代理類重新用於代理的後續生成。 – 2009-10-28 13:47:00

0

文章"How to reuse types across service endpoints"建議在客戶端手動更新Reference.svcmap包括多個與NamespaceMappings。

或者,svcutil確實允許您在一次指定多個端點並使用/ r(/ reference)和/ n(/ namespace)參數。