我在 Visual Studio 中创建了一个演示 .net Web 服务,并尝试使用 localhost 在本地浏览器中运行。这给出了以下错误之一:
1) 当我的地址 = IP + 端口号时 XML 拉解析器异常
2) 当我的地址 = 模拟器端口 + 本地端口时出现未知主机异常
3) 当我的地址 = localhost + 端口号时,连接异常连接本地主机失败
如何使用 CMD 创建 AVD?
我在 Visual Studio 中创建了一个演示 .net Web 服务,并尝试使用 localhost 在本地浏览器中运行。这给出了以下错误之一:
1) 当我的地址 = IP + 端口号时 XML 拉解析器异常
2) 当我的地址 = 模拟器端口 + 本地端口时出现未知主机异常
3) 当我的地址 = localhost + 端口号时,连接异常连接本地主机失败
如何使用 CMD 创建 AVD?
If You Want to call Rest Webservice than Here Is the Code:
class LongOperation extends AsyncTask<String, String, String>{
@Override
// http://stackoverflow.com/questions/3505930/make-an-http-request-with-android
protected String doInBackground(String... uri) {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
String responseString = null;
try {
response = httpclient.execute(new HttpGet(uri[0]));
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
out.close();
responseString = out.toString();
} else{
//Closes the connection.
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
return responseString;
}
If You Want to call WCF/asmx Webservice than Here Is the Code:
Here You have to use KSOAP2 library
private final String NAMESPACE = "http://tempuri.org/";
private final String URL = "[http://10.0.2.2:8085/Service1.svc][1]";
//Use Service1.asmx for asmx service
private final String SOAP_ACTION = "http://tempuri.org/GetData";
private final String METHOD_NAME = "GetData";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
Log.i("myApp_Responce...", response.toString());
TextView tv= (TextView)findViewById(R.id.textView1);
tv.setText(response.toString());
} catch (Exception e)
{
e.printStackTrace();
}