0

我在asp.net中创建了restfull webservices(retun json data)并将其部署在iis上。现在我想在android中使用那个webServices ..但在android中它在模拟器中工作正常但在android设备上它给出错误......

错误:连接到“// http://ipAddress.:6547/ ”被拒绝请帮助那是代码

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.recent_jsonws_map_layout);


}


 public String readJSONFeed(String URL)
 {
        StringBuilder stringBuilder = new StringBuilder();
        HttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(URL);
        try
        {
            HttpResponse response = httpClient.execute(httpGet);
            StatusLine statusLine = response.getStatusLine();
            int statusCode = statusLine.getStatusCode();
            if (statusCode == 200)
            {
                HttpEntity entity = response.getEntity();
                InputStream inputStream = entity.getContent();
                BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
                String line;
                while ((line = reader.readLine()) != null)
                {
                    stringBuilder.append(line);
                }
                inputStream.close();
            }
            else
            {
                Log.d("JSON", "Failed to download file");
            }
        }
        catch (Exception e)
        {
            Log.e("readJSONFeed", e.getLocalizedMessage());
        }        
        return stringBuilder.toString();
   }


 @SuppressWarnings("unused")
 private class ReadWeatherJSONFeedTask extends AsyncTask<String, Void, String>
 {
        protected String doInBackground(String... urls)
        {
            return readJSONFeed(urls[0]);
        }

        protected void onPostExecute(String result)
        {
            try
            {
                jsonObject = new JSONObject(result);
                jsonArrayGeoPoint = new JSONArray(jsonObject.getString("jsondataResult").toString());
                Toast.makeText(getApplicationContext(), jsonArrayGeoPoint.getString(0).toString()+"||"+jsonArrayGeoPoint.getString(1).toString(), Toast.LENGTH_SHORT).show();

                String[] strArrtemp=new String[5];
                Double[] strArrLat = new Double[5];
                Double[] strArrLon = new Double[5];

                for(int i=0; i<jsonArrayGeoPoint.length(); i++)
                {
                    try
                    {
                        strArrtemp[i]=jsonArrayGeoPoint.getString(i).toString();

                    }
                    catch (JSONException e)
                    {
                        Log.e("JsonArray ERROR",e.getLocalizedMessage());
                    }
                }

                String[] arrytemp = new String[2];
                String temp;

                for(int i=0; i<strArrtemp.length; i++)
                {   
                    temp = strArrtemp[i].toString();
                    strArrLat[i]=Double.parseDouble(temp.substring(0,6));
                    strArrLon[i]=Double.parseDouble(temp.substring(7,13));
                }
                Toast.makeText(getApplicationContext(), "Lat1="+strArrLat[1].toString()+" & Lon1="+strArrLon.toString(), Toast.LENGTH_SHORT).show();
            Button getDir;
            getDir = (Button)findViewById(R.id.getLocationBtn);
            getDir.setText(strArrLat[1].toString());


            }
            catch (Exception e)
            {
                Log.e("ReadWeatherJSONFeedTask", e.getLocalizedMessage());
            }          
        }
 }





enter code here


 public void btnGetWeather(View view)
 { newReadWeatherJSONFeedTask().execute(http://ipAddress.:6547/RestServiceImpl.svc/jsondata/");
 }

}

4

1 回答 1

0

而不是使用 localhost 使用 10.0.2.2:portnumber

于 2013-12-08T06:48:03.547 回答