2011-06-16 81 views
0

我有一个类如何列表<T>张贴到WCF REST服务

[DataContract] 
public class Test 
{ 
[DataMemeber] 
public string A {get;set;} 
[DataMemeber] 
public string B {get;set;} 
[DataMemeber] 
public string C {get;set;} 
} 

我有一个RESTful的WCF方法

[WebInvoke(UriTemplate = "checkupdates", 
ResponseFormat = WebMessageFormat.Json, 
BodyStyle=WebMessageBodyStyle.WrappedRequest)] 

List<Test> CheckForUpdates(List<Test> testing); 

我怎样才能发布List对象的服务?这是来自wpf客户端。

由于

回答

1

列表相当于一个数组,所以该值应被表示为一个JSON阵列。而且由于车身造型说,请求需要包装,那么你应该用一个命名为参数字段包裹JSON数组中的对象:

{"testing":[ 
    {"A":"Value of A1","B":"Value of B1","C":"Value of C1"}, 
    {"A":"Value of A2","B":"Value of B2","C":"Value of C2"}, 
    {"A":"Value of A3","B":"Value of B3","C":"Value of C3"}]} 

如果该请求没有被包(裸BodyStyle或WrappedResponse),那么你将不需要包装对象,这将是一个请求的操作:

[ 
    {"A":"Value of A1","B":"Value of B1","C":"Value of C1"}, 
    {"A":"Value of A2","B":"Value of B2","C":"Value of C2"}, 
    {"A":"Value of A3","B":"Value of B3","C":"Value of C3"} 
] 
+0

是否有可能给你一个例子。将改变BodyStyle使生活更容易? – Bullish 2011-06-16 14:26:58

+0

如果BodyStyle是Bare(或WrappedResponse,意味着请求未被包装),那么你不需要包装对象 - 我会更新与Bare案例的请求的答案。 – carlosfigueira 2011-06-16 16:00:36