我正在尝试从 REST WCF 服务返回通用 ICollection。以下应该可行吗?
[ServiceContract]
public class WebConfigurationManager {
[WebGet]
[OperationContract]
public ICollection<string> GetStrings() {
return new string[] { "A", "B", "C" };
}
}
当我尝试从网络浏览器执行此操作时,出现错误。查看我的 WCF 跟踪显示了这一点:
无法序列化类型“System.String[]”的参数(对于操作“GetStrings”,合同“WebConfigurationManager”),因为它不是方法中的确切类型“System.Collections.Generic.ICollection`1[System.String]”签名且不在已知类型集合中。为了序列化参数,请使用 ServiceKnownTypeAttribute 将类型添加到操作的已知类型集合中。
这应该有效:
[ServiceKnownType(typeof(string[]))]
[ServiceContract]
public class WebConfigurationManager {
[WebGet]
[OperationContract]
public ICollection<string> GetStrings() {
return new string[] { "A", "B", "C" };
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)