[英]WCF REST Return List in Json
I want to respond a List in WCF with Rest in JSON format. 我想用REST格式以WCF格式响应列表。 How can i do that to receive my Users?
我该怎么做才能收到我的用户? Endpointconfiguration already works.
端点配置已经有效。
[OperationContract(Name = "GetUsers")]
[WebGet(UriTemplate = "GetUsers", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
List<User> GetUsers();
My problem was that i had a class defined in the IInterface.cs. 我的问题是我在IInterface.cs中定义了一个类。 But in that class I had a subclass, lets say for example "dog".
但是在该类中,我有一个子类,比如说“狗”。
Now I set up the [DataContract] for "user", but not for "dog", which was unfortunately included into "user". 现在,我为“用户”设置了[DataContract],但没有为“狗”设置[DataContract],不幸的是,它包含在“用户”中。
Solution: "For every class that should be returned, dont forgett the [DataContract]" 解决方案:“对于应该返回的每个类,请不要忘记[DataContract]”
The tricky thing on that stuff is, you dont even have any warnings, exceptions etc. 在这些东西上棘手的事情是,您甚至没有任何警告,异常等信息。
Greets and thanks! 谢谢,谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.