Java 无法从Android中的Web服务进行分析
我在使用此代码时遇到了Java 无法从Android中的Web服务进行分析,java,android,web-services,Java,Android,Web Services,我在使用此代码时遇到了异常,但它与其他链接一起工作 public class WebserviceCall { static WebserviceCall com; String namespace = "http://tempuri.org/"; private String url = "http://sicsglobal.co.in/T-Drive/WebService_TDrive.asmx"; String SOAP_ACTION; SoapO
异常
,但它与其他链接一起工作
public class WebserviceCall {
static WebserviceCall com;
String namespace = "http://tempuri.org/";
private String url = "http://sicsglobal.co.in/T-Drive/WebService_TDrive.asmx";
String SOAP_ACTION;
SoapObject request = null, objMessages = null;
SoapSerializationEnvelope envelope;
AndroidHttpTransport androidHttpTransport;
public static WebserviceCall getInstance() {
if (com == null)
return new WebserviceCall();
else
return com;
}
protected void SetEnvelope() {
try {
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
androidHttpTransport = new AndroidHttpTransport(url);
androidHttpTransport.debug = true;
} catch (Exception e) {
System.out.println("Soap Exception SetEnvelope (); \n"
+ e.toString());
}
}
public String getConvertedWeight(String MethodName, String thisUsername,
String thisPassword) {
try {
SOAP_ACTION = namespace + MethodName;
request = new SoapObject(namespace, MethodName);
request.addProperty("userId", "" + thisUsername.trim());
request.addProperty("password", thisPassword.trim());
SetEnvelope();
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
String result = envelope.getResponse().toString();
return result;
} catch (Exception e) {
return e.toString();
}
} catch (Exception e) {
// TODO: handle exception
return e.toString();
}
}
}
您应该准备soap请求,然后才能执行正确的http请求,因为您连接的Web服务是soap服务,因此您可以使用它来准备soap请求 还可以看看这里尝试使用Asynctask
private class Task extends AsyncTask<String, Void, String> {
protected void onPreExecute() {
}
@Override
protected String doInBackground(String... urls) {
//your code here
return response;
}
@Override
protected void onPostExecute(String response) {
//treat the response here
}
}
私有类任务扩展了异步任务{
受保护的void onPreExecute(){
}
@凌驾
受保护的字符串doInBackground(字符串…URL){
//你的代码在这里
返回响应;
}
@凌驾
受保护的void onPostExecute(字符串响应){
//在这里处理响应
}
}
寻找更多关于它的信息
如果这不起作用,请发布日志猫。大多数情况下都是这样,因为需要在“此处输入代码”部分输入代码发布日志猫输出仍然存在同样的问题