0

我的 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

4

2 回答 2

1

你需要有如下的网址

String url = "http://10.0.2.2/WSCom.svc/ValidateLogin/YourUserId/Password";

当您在 url 中传递数据时,您不需要使用

setparameters(url , new UrlEncodedFormEntity(httgetArgs));
于 2013-10-03T09:54:31.177 回答
1
String user = "";
String pass = "";
String url = "http://10.0.2.2/WSCom.svc/ValidateLogin/" + user + "/" + pass;
于 2013-10-03T11:27:16.057 回答