Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Android客户端调用web服务_Android_Wcf - Fatal编程技术网

从Android客户端调用web服务

从Android客户端调用web服务,android,wcf,Android,Wcf,我正在同时做我的第一个Android应用程序和第一个WCF服务 我有以下服务合同: [ServiceContract] public interface ILoginService { [OperationContract] string Login(string username, string password); // TODO: Add your service operations here } 我想从我的A

我正在同时做我的第一个Android应用程序和第一个WCF服务

我有以下服务合同:

[ServiceContract]
    public interface ILoginService
    {

        [OperationContract]
        string Login(string username, string password);

        // TODO: Add your service operations here
    }
我想从我的Android应用程序调用它,并传入用户名和密码参数。 1.这份作业合同适合这份工作吗? 2.有人能告诉我如何通过Android调用WCF服务的教程/代码示例吗

谢谢大家!

编辑:我可能离你更近一点,但我还是迷路了。 以下是我到目前为止的情况: 合同:

[OperationContract]
        [WebGet(ResponseFormat= WebMessageFormat.Json,
            UriTemplate="/LoginService/?username={username}&password={password}")]
        Response Login(string username, string password);
然后我通过以下方式从Android调用该服务:

public LoginResponse RemoteLogin(String username, String password)
    {
        loginParameters = "/LoginService/username=" + username + "&password=" + password;


        HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet(serviceAddress + loginParameters);

        HttpResponse response;

        LoginResponse loginResponse = null;

        try
        {
            response = httpclient.execute(httpget);

            HttpEntity entity = response.getEntity();

            if(entity != null)
            {
                InputStream instream = entity.getContent();
                String result = convertStreamToString(instream);
                JSONObject json = new JSONObject(result);

                // Parsing
                JSONArray nameArray = json.names();
                JSONArray valArray = json.toJSONArray(nameArray);

                loginResponse = new LoginResponse(valArray.getBoolean(1), valArray.getString(0), valArray.getString(2));


                instream.close();
            }

        }
        catch(Exception e)
        {
            loginResponse = new LoginResponse();
            String sDummy = e.toString();
        }
        return loginResponse;
    }

我不知道现在出了什么问题。

没有真正解决问题,只是有点回避了。
我从web.config中删除了与ServiceModel有关的任何内容,并将ServiceHostFactory指令添加到SVC文件中。这就成功了。现在一切正常。这一定是某种配置问题。

您能解释一下如何在android中启动wcf服务吗。请给出一些启动步骤。我对此一无所知,所以