1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
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;
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
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;
}
}
|