在 WCF 中传递复杂类型作为结果有什么问题?
我有以下 WCF 方法:
[OperationContract]
array<Object^>^ GetResult(UInt64 taskId);
[OperationContract]
array<UrlInfo^>^ GetResultAsUriInfo(UInt64 taskId);
当我通过 GetResult 返回字符串数组时,它工作正常。另外,当我通过 GetResultAsUriInfo 返回 UrlInfo 数组时,它可以正常工作。但是,当我尝试通过 GetResult 返回 UrlInfo 的 appay 时,我收到以下客户端异常:
The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be
used for communication because it is in the Faulted state.
内部异常为 null。
以下是 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 数组作为对象数组返回?
I've got following WCF methods:
[OperationContract]
array<Object^>^ GetResult(UInt64 taskId);
[OperationContract]
array<UrlInfo^>^ GetResultAsUriInfo(UInt64 taskId);
when I do return array of strings through GetResult, it works fine. Also, when I return array of UrlInfo through GetResultAsUriInfo it works without any problems. However, when I'm trying to return appay of UrlInfo through GetResult, I'm getting following client side exception:
The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be
used for communication because it is in the Faulted state.
the inner exception is null.
Here's the definition for 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; }
}
Why can't I return an array of UrlInfo as array of objects?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
wcf 只能传递已知类型而不是泛型类型 - 但我不熟悉 C++ 语法。
但如果需要,您可以为您的类型编写自己的序列化器。
编辑:我真的应该更仔细地阅读这个问题。问题是
对象类型中的对象类型无法在 WCF 中序列化。你应该使用你期望的类型。
wcf can just pass knowntypes and not generic types - but i m not familiar with c++ syntax.
but you can write your own serializer for your types if you need.
EDIT: i really should read the question more carefully. the problem is your object type in
object type can't be serialized in WCF. you should ues the type you expect there.