试图存取权限采用Android本地WebService时,连接被拒绝 [英] Connection refused when trying to acces local webservice using Android
问题描述
我创造建在Visual Basic 2010的服务器,但该程序可以插入/更新/删除,我使用的数据库。我创建了用于同步服务器与在机器人在数据库上的数据库的本地Web服务
I am creating a server built in Visual Basic 2010 and that program can insert/update/delete to a database that I use. I created a local Web Service that is used to synchronize the database on the server with the database in Android.
我用下面的Android code:
I use the following Android code :
package com.zelacroix.bukumenu;
import java.io.IOException;
import java.io.InputStream;
import org.apache.http.*;
import org.apache.http.client.*;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.params.*;
import org.apache.http.impl.client.DefaultHttpClient;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
public class Sinc extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sinc);
Toast.makeText(getApplicationContext(), getKategori(), 5).show();
}
public String getKategori(){
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 60000);
HttpConnectionParams.setSoTimeout(httpParameters, 60000);
HttpClient client=new DefaultHttpClient(httpParameters);
HttpPost httpPost = new HttpPost("http://192.168.1.2:1924/TugasAkhir/Service.asmx/getKategori");
HttpResponse response;
String result="";
try
{
response=client.execute(httpPost);
HttpEntity entity= response.getEntity();
DataHandler dataHandler = new DataHandler();
if (entity!=null)
{
InputStream instream = entity.getContent();
result = dataHandler.convertStreamToString(instream);
instream.close();
}
} catch (ConnectTimeoutException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), e.toString(), 100).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), e.toString(), 100).show();
}
return result;
}
}
我得到一个错误:
org.apache.http.conn.httphostconnectexception连接
``HTTP://192.168.1.2:1924年.....拒绝
I get an error :
org.apache.http.conn.httphostconnectexception connection to
``http://192.168.1.2:1924..... refused
有关您的信息.. 这code运行成功时,我使用的是仿真器和更改IP地址为10.0.2.2。
For your information.. This code runs successfully when I'm using the emulator and change the IP address to 10.0.2.2.
这code也成功运行,当我访问一个托管的在线网络服务。 它不但不能当我运行的Web服务作为地方并尝试使用我的笔记本电脑的IP(192.168.1.2)与Android设备进行访问。
This code also run successfully when I access a hosted online web service. It fails only when I run the web service as local and try to access it with an Android device using my laptop's IP (192.168.1.2).
我使用WIFI。
我该如何解决这个问题?
How can I fix this error?
推荐答案
最后的解决......问题是Visual Studio 2010中,以便在设置IIS复杂的,然后我尝试developt我的web服务的Visual Studio 2008和IIS工作精细! Android的可访问Web服务没有拒绝连接。
finally its solved.. the problem is visual studio 2010 so complicated in setting the IIS, then i try to developt my web service on Visual studio 2008 and IIS work fine! the Android can access the web service without connection refused.
这篇关于试图存取权限采用Android本地WebService时,连接被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!