android中ksoap2异常处理
我在下面的代码中遇到异常android中ksoap2异常处理,android,exception,exception-handling,ksoap2,android-ksoap2,Android,Exception,Exception Handling,Ksoap2,Android Ksoap2,我在下面的代码中遇到异常 package com.dipl.smpm.smpm; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapPrimitive; import org.ksoap2.serialization.SoapSerializationEnvelope; impor
package com.dipl.smpm.smpm;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.ksoap2.transport.HttpTransport;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
public class ConnectHttp extends Activity {
private static final String SOAP_ACTION = "http://tempuri.org/loginDetails";
private static final String METHOD_NAME = "loginDetails";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://localhost:88/EmpService.asmx";
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv=(TextView)findViewById(R.id.textView11);
SoapObject sobj_requestLogin=new SoapObject(NAMESPACE, METHOD_NAME);
sobj_requestLogin.addProperty("username", "a");
sobj_requestLogin.addProperty("password", "a");
SoapSerializationEnvelope spenve_Login = new SoapSerializationEnvelope(SoapEnvelope.VER11);
spenve_Login.dotNet=true;
spenve_Login.setOutputSoapObject(sobj_requestLogin);
AndroidHttpTransport htrans_login= new AndroidHttpTransport(URL);
try{
Toast.makeText(getApplicationContext(), "1", Toast.LENGTH_SHORT).show();
htrans_login.call(SOAP_ACTION,spenve_Login);
Toast.makeText(getApplicationContext(), "2", Toast.LENGTH_SHORT).show();
SoapPrimitive spprim_login=(SoapPrimitive)spenve_Login.getResponse();
Toast.makeText(getApplicationContext(), "3", Toast.LENGTH_SHORT).show();
tv.setText("result: "+spprim_login+" ");
Toast.makeText(getApplicationContext(), "4", Toast.LENGTH_SHORT).show();
}
catch(Exception e){
Toast.makeText(getApplicationContext(), "Exception", Toast.LENGTH_LONG).show();
}
}
}
我成功地得到了一个祝酒词“1”,但在祝酒词“2”到来之前,它将成为“例外”祝酒词。帮帮我,我犯了什么错?另外,我使用2.3 ksoap2 2.3 jar作为用户定义库。像这样使用
final String SOAP_ACTION = "http://tempuri.org/loginDetails";
final String METHOD_NAME = "loginDetails";
final String NAMESPACE = "http://tempuri.org/";
final String URL = "http://localhost:88/EmpService.asmx";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("username", "a");
request.addProperty("password", "b");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
try {
ht.call(SOAP_ACTION, envelope);
final SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
String str = response.toString();
}
catch (Exception e)
{
e.printStackTrace();
}
在manifest.xml中添加此行:
像这样使用
final String SOAP_ACTION = "http://tempuri.org/loginDetails";
final String METHOD_NAME = "loginDetails";
final String NAMESPACE = "http://tempuri.org/";
final String URL = "http://localhost:88/EmpService.asmx";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("username", "a");
request.addProperty("password", "b");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
try {
ht.call(SOAP_ACTION, envelope);
final SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
String str = response.toString();
}
catch (Exception e)
{
e.printStackTrace();
}
在manifest.xml中添加此行:
我刚刚将URL中的localhost更改为本地系统的ip。
问题解决了。感谢@NIRMAL我刚刚将URL中的localhost更改为本地系统的ip。
问题解决了。感谢@NIRMAL请发布日志。日志中没有错误。。。。如果有必要,我会上传,但它会“异常”吗??您得到了什么异常?它的xml解析器异常、Soap错误异常和IOException请发布日志猫。日志猫中没有错误。。。。如果有必要,我会上传,但它会“异常”吗??您遇到了什么异常?它的xml解析器异常、Soap错误异常和IOException。然后,问题可能是您的参数用户名和密码。这与您在Web服务中使用的参数相同吗?是的,相同。我是否也应该包括响应参数名称???我不知道web服务实际上是如何编写的。我的一个朋友帮我在这里发布了你的网站服务?对不起,我不能透露(.我从开发人员那里得到了严重警告不要这样做。它首先是IOException。什么可能会被破坏???看我编辑的答案你是否在manifest.xml中添加了它?然后,问题可能是你的参数用户名和密码。这是你在Web服务中使用的同一个参数吗?是的,相同。我应该包括响应参数名称吗另外???我不知道web服务实际上是如何编写的。我的一个朋友帮我在这里发布了你的web服务?很抱歉,我不能透露它。:(。我从开发人员那里得到了严重警告,不要这样做。它首先是IOException。什么可能会被破坏???看我编辑过的答案。你在manifest.xml中添加了吗?