【发布时间】:2011-06-17 10:25:37
【问题描述】:
我正在尝试从应以 json 格式传递一些数据的 android 客户端联系 RESTful WCF POST Web 服务。我已经成功联系了一个 RESTful WCF GET 网络服务,但我无法弄清楚 POST 版本是如何工作的。
这是进行调用的android客户端代码:
HttpPost request = new HttpPost(uri);
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
/*... Building the NameValuePairs object ... */
request.setEntity(new UrlEncodedFormEntity(nameValuePairs));
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
/* ... handling the response ...*/
这是 WCF Web 服务代码:
[WebInvoke(Method = "POST",
UriTemplate = "ServiceActivation",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
string MyPostMethod();
public string MyPostMethod()
{
try
{
/*...*/
}
catch (Exception e)
{
/*...*/
}
}
这样android客户端就成功联系到web服务了;但我不知道如何在 MyPostMethod 中检索从 android 客户端传递的数据。像这样:MyPostMethod(string data) 以来自 android 客户端的错误请求结束。
那么,在 Web 服务中检索传递的数据的方法是什么?
提前致谢!
【问题讨论】: