80,351
社区成员
发帖
与我相关
我的任务
分享
import java.io.IOException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import android.util.Log;
public class MyWebServiceHelper {
// WSDL文档中的命名空间
private static final String targetNameSpace = "http://service.main";
// WSDL文档中的URL
private static final String WSDL = "http://localhost:8181/webTest/services/IPersonImp";
//需要调用的方法名(获得Myervices中的login方法)
private static final String login="login";
public String login(String uname, String pwd){
String reutrnResult = null;
SoapObject request =new SoapObject(targetNameSpace,login);
request.addProperty("uname", uname);
request.addProperty("pwd", pwd);
Log.i("mylog", "request---" + request);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = false;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTranstation = new HttpTransportSE(WSDL);
try {
Log.i("mylog", "info---" + httpTranstation);//日志打印到这里,就转入下面catch (IOException e)部分
httpTranstation.call(targetNameSpace+login, envelope);
Log.i("mylog", "info");
if(envelope.getResponse() != null){
SoapObject soapObject = (SoapObject) envelope.getResponse();
Log.i("mylog", "用户名--------"+soapObject.getProperty("name"));
Log.i("mylog", "密码--------"+soapObject.getProperty("pwd"));
reutrnResult = "ok";
}
} catch (IOException e) {
Log.e("mylog", "error------1111");
e.printStackTrace();
reutrnResult = "连接WSDL失败--1";//运行时android界面返回这个结果
} catch (XmlPullParserException e) {
Log.e("mylog", "error------2222");
reutrnResult = "连接WSDL失败--2";
e.printStackTrace();
}
return reutrnResult;
}
}
public class IPersonImp implements IPerson {
PersonDAO comdao=new PersonDAO();
//得到所有用户列表
public List<Person> getCompanyList() {
List<Person> list=new ArrayList<Person>();
try {
list=comdao.getCompanyList();
} catch (SQLException e) {
e.printStackTrace();
list=null;
}
return list;
}
public String login(String uname, String pwd) {
// TODO Auto-generated method stub
Person com = new Person();
com = comdao.login(uname, pwd);
String result = "fail";
if(com != null){
result = "success";
}
return result;
}
}