创建WCF Restful服务返回多个响应对象 [英] Create WCF Restful service returning multiple response object
问题描述
我必须使用c#在.net中创建WCF Restful服务,我知道需要定义WCF Restful服务的属性,但我的查询是如何从一个响应对象和响应对象中的不同类发送响应应该在Json中。
就像我有类用户有字段ID,用户名和列表< role>
公共类用户
{
public int id {get;组; }
public String username {get;组; }
public List< role>角色{get;组; }
}
所以我想知道如何在id和username的同一个响应对象中添加Role of Role响应。 />
再次角色类有另一个操作列表
公共类角色
{
public String username {get;组; }
public List< operation>操作{get;组; }
}
所以我想知道如何添加操作和角色列表到同一个id和用户名的响应
Hi ,
I have to create WCF Restful service in .net with c# , i aware about attribute which need to define WCF Restful service , But my query is how to send response from different classes in one response object and response object should be in Json.
Like i have class User having fields id, username and List<role>
public class User
{
public int id { get; set; }
public String username { get; set; }
public List<role> roles { get; set; }
}
So i want to know how to add List of Role response in the same response object of id and username.
Again Role class has another list of operation
public class Role
{
public String username { get; set; }
public List<operation> operations { get; set; }
}
So i want to know how to add list of Operation and Role to the same response of id and username
推荐答案
[DataContract]
public class User
{
[DataMember]
public int id { get; set; }
[DataMember]
public String username { get; set; }
[DataMember]
public List<roles> roles { get; set; }
[DataMember]
public List<response> response{ get; set; }
}
add this in interface.
[OperationContract]
[WebGet]
list<user> GetUserDetails(int id)
</user></response></roles>
谢谢
saravanan
thanks
saravanan
这篇关于创建WCF Restful服务返回多个响应对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!