我运行一个测试,返回一个动态对象(ExpandoObject)作为响应。
它可以工作,但 JsonServiceClient 无法转换对象
并以 json 格式返回数据和类型描述。
我们能做得更好吗?
public class DynamicAPIRequest : IReturn<object>
{ ... }
public object Post(DynamicAPIRequest request)
{
dynamic response = new ExpandoObject();
response.Name = "Donald Duck";
response.Nephews = new List<nephew>();
response.Nephews.Add(new nephew { name = "Huey" } );
...
return response;
}
在客户端
var nephews = client.Post<object>(new DynamicAPIRequest { uncle = "skroutz" });
/* returns
{Name:Donald Duck,Nephews:[{__type:Test.Client.Model.nephew,
Test.Client.Model,name:Huey},{name:Dewey},{name:Louie}]}
*/
我还能做什么?