从Android设备连接到本地IIS上的WCF RESTful服务(Galaxy Note 3)

时间:2014-03-11 00:52:48

标签: android wcf iis httpclient

我正在构建一个需要连接到WCF服务的Android应用程序。我开发了一个并将其托管在我的本地IIS(7.5)上的以下URL:http://129.168.125.5/MyAppDomain/RESTService.svc

(我使用本地IP地址而不是localhost来避免引用同一设备或使用10.0.0.2)。它在模拟器上工作正常,但当我尝试使用Eclipse从我通过USB(galaxy note 3)连接的有源设备进行调试时,

I always got connection to http://129.168.125.5 refused

我还在我的清单文件中授予了INTERNET 的权限。请帮忙吗?

这是我的代码示例:

Boolean res = false;
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost("http://129.168.125.5/MobileShopper/ShopperService.svc/Login");
        post.setHeader("Accept", "application/json");
        post.setHeader("Content-type", "application/json");

        try
          {
            JSONObject obj = new JSONObject(); 
            obj.put("email", mEmail);
            obj.put("password", mPassword);
            StringEntity entity = new StringEntity(obj.toString());
            post.setEntity(entity);
            HttpResponse response = client.execute(post);
            HttpEntity Hentity = response.getEntity();
            if(Hentity.getContentLength() != 0) {
                // stream reader object
                Reader JSONReader = new InputStreamReader(response.getEntity().getContent());
                //create a buffer to fill if from reader
                final char[] buffer = new char[(int) response.getEntity().getContentLength()];
                //fill the buffer by the help of reader
                JSONReader.read(buffer);
                //close the reader streams
                JSONReader.close();

                if(new String(buffer).equals("1")){
                    res = true;
                }
                else
                    res = false;            
            }


          }catch(Exception e)
          {
              Log.e("Error", e.getMessage());
              return false;
          }
        return res;

0 个答案:

没有答案