我的 android 应用程序正在调用 WCF Web 服务,但我无法发送我的 get 请求:
这是我的 WCF 合同
[OperationContract]
[WebGet(UriTemplate = "ValidateLogin/{userId}/{password}",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped)]
LoginValidation ValidateLogin(string userId, string password);
我在我的 Android 应用上调用它
public String ValidateLogin(ArrayList<NameValuePair> httgetArgs){
String result = "";
String url = "http://10.0.2.2/WSCom.svc/ValidateLogin";
InputStream is = null;
try {
HttpClient httpclient = new DefaultHttpClient();
setparameters(url , new UrlEncodedFormEntity(httgetArgs));
HttpGet httget = new HttpGet(url);
httget.setHeader("Accept", "application/json");
httget.setHeader("Content-Type", "application/json");
HttpResponse response = httpclient.execute(httget);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}
catch (Exception e) {
result = e.toString();
}
try {
result = readStream(is);
is.close();
}
catch (Exception e) {
result = e.toString();
}
return (result);
}
但我得到了错误
合约“IWSCom”中的“ValidateLogin”操作使用 GET,但也有主体参数“userId”。GET 操作不能有主体。将参数“userId”设为 UriTemplate 参数,或从 WebGetAttribute 切换到 WebInvokeAttribute