WCF WebGet 和 ICollection<>
我正在尝试从 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 将类型添加到操作的已知类型集合中。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该有效:
This should work:
安德鲁为我指明了正确的方向。 答案是
在[ServiceContract]属性上方添加。
Andrew pointed me in the right direction. The answer is to add
above the [ServiceContract] attribute.