9
Iam試圖將我的應用程序連接到我在asp.net中創建的WCF服務。 服務在我的本地機器上運行: http://localhost:8080/Service.svc/Android應用程序連接到web服務 - 不工作
但由於某些原因,我的Android無法連接到此http-adress。
這是錯誤:
09-12 14:50:44.540:WARN/System.err的(593):org.apache.http.conn.HttpHostConnectException:連接到http://127.0.0.1:8080拒絕
這是wcf中的方法,Iam試圖返回具有一些值的集合。
/// <returns>An enumeration of the (id, item) pairs. Returns null if no items are present</returns>
protected override IEnumerable<KeyValuePair<string, SampleItem>> OnGetItems()
{
// TODO: Change the sample implementation here
if (items.Count == 0)
{
items.Add("A", new SampleItem() { Value = "A" });
items.Add("B", new SampleItem() { Value = "B" });
items.Add("C", new SampleItem() { Value = "C" });
}
return this.items;
}
這是在android的連接的樣子:
public void getData(String url)
{
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse response;
try
{
response = httpClient.execute(httpGet);
Log.i(TAG,response.getStatusLine().toString());
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}/* catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} */catch (Exception e){
e.printStackTrace();
}finally{
httpGet.abort();
}
}
感謝它的工作, – Troj 2010-09-12 17:04:13
你知道它是如何可以讀取所發送的數據? – Troj 2010-09-12 17:04:32
您可以在主機上使用WireShark來達到此目的。 – 2010-09-12 19:45:46