2012-01-29 24 views
0

我有以下WCF方法:因爲在WCF中傳遞複雜類型會出現什麼問題?

[OperationContract] 
array<Object^>^ GetResult(UInt64 taskId); 

[OperationContract] 
array<UrlInfo^>^ GetResultAsUriInfo(UInt64 taskId); 

當我通過調用getResult返回一個字符串數組,它工作正常。另外,當我通過GetResultAsUriInfo返回UrlInfo數組時,它沒有任何問題。然而,當我試圖通過調用getResult返回appay UrlInfo的,我得到下面的客戶端異常:

The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be 
used for communication because it is in the Faulted state. 

的內部異常是空的。

這裏的定義UrlInfo:

[Serializable] 
[DataContract] 
public class UrlInfo 
{ 
    Uri uri; 

    [DataMember] 
    public Uri Uri 
    { 
     get { return uri; } 
     set { uri = value; } 
    } 
    string title; 

    [DataMember] 
    public string Title 
    { 
     get { return title; } 
     set { title = value; } 
    } 

    string description; 
    [DataMember] 
    public string Description 
    { 
     get { return description; } 
     set { description = value; } 
    } 

    List<string> tags = new List<string>(); 
    [DataMember] 
    public List<string> Tags 
    { 
     get { return tags; } 
     set { tags = value; } 
    } 

    Dictionary<string, string> allMetadata = new Dictionary<string, string>(); 
    [DataMember] 
    public Dictionary<string, string> AllMetadata 
    { 
     get { return allMetadata; } 
     set { allMetadata = value; } 
    } 


    string[] categoryPreferences = new string[0]; 

    [DataMember] 
    public string[] CategoryPreferences 
    { 
     get { return categoryPreferences; } 
     set { categoryPreferences = value; } 
    } 

爲什麼我不能返回UrlInfo數組作爲對象的數組?

+0

你可以發佈一些代碼,顯示你如何試圖返回urlinfo數組作爲對象數組? – Rajesh 2012-01-30 09:57:22

回答

2

wcf只能傳遞知識類型而不是泛型類型 - 但我不熟悉C++語法。

但您可以根據自己的需要編寫自己的序列化程序。

編輯:我真的應該更仔細地閱讀這個問題。問題是您的對象類型

array<Object^>^ GetResult(UInt64 taskId); 

對象類型無法在WCF中序列化。你應該選擇你期望的類型。

+0

UrlIndo不是通用的,它的代碼在c#中 – 2012-01-30 08:08:11

+0

^你的數組中^是什麼^GetResultAsUriInfo(UInt64 taskId);? – blindmeis 2012-01-30 08:36:52

+0

坦率地說,我不知道,但cli C++不會在沒有這個東西的情況下創建託管類型)) – 2012-01-30 15:28:11

相關問題