public final class Decler {
public final static String serviceUrl = "http://192.168.1.66:8080/ecenter/services/ClientLinkService";
public final static String methodName = "addUser"; //方法名
public final static String NAMESPACE = "http://tempuri.org/"; //命名空间
public final static String WEB_METHOD = NAMESPACE+methodName;
private static final int CONNECT_TIMEOUT = 1000;
private static final int SOCKET_TIMEOUT = 1000;
public static final String ipAddress = ""; //Ip地址
public final static int dstPort = 9999;
}
客户端代码:
public class Clients {
public SoapObject so;
public SoapSerializationEnvelope sse;
Userinfo user = new Userinfo();
public Userinfo methodCilents(String username, String password) {
// ①创建soapObject对象,传递命名空间和方法名
so = new SoapObject(Decler.NAMESPACE, Decler.methodName);
// ②设置webService的方法参数
so.addAttribute("username", username);
so.addAttribute("password", password);
// ③申明soapserializationEnvelope,定义其版本
sse = new SoapSerializationEnvelope(SoapEnvelope.VER11);
sse.bodyOut = so;
sse.dotNet = false;
sse.setOutputSoapObject(so);
method();
return user;
}
// 注册
public int addUser(Userinfo user) {
// ①创建soapObject对象,传递命名空间和方法名
so = new SoapObject(Decler.NAMESPACE, Decler.methodName);
// ②设置webService的方法参数
so.addAttribute("user", user);
// ③申明soapserializationEnvelope,定义其版本
sse = new SoapSerializationEnvelope(SoapEnvelope.VER11);
sse.bodyOut = so;
sse.dotNet = false;
sse.setOutputSoapObject(so);
method();
return 0;
}
public void method() {
// 设置bodyOut属性
sse.bodyOut = so;
// ④ 创建HttpTransportSE对象,并指定WSDL文档的URL
HttpTransportSE ht = new HttpTransportSE(Decler.serviceUrl);
try {
// ⑤调用WebService
ht.call(Decler.WEB_METHOD, sse);
if (sse.getResponse() != null) {
// ⑥使用getResponse方法获得WebService方法的返回结果
SoapObject soapObject = (SoapObject) sse.getResponse();
// 通过getProperty方法获得Product对象的属性值
String result = "username:"
+ soapObject.getProperty("username") + "/n";
result += "password:" + soapObject.getProperty("password");
} else {
System.out.println("没有");
}
} catch (Exception e) {
e.getMessage();
System.out.println(e.getMessage());
}
}
}
activity里面的点击注册代码:
public void register() {
new Thread() {
public void run() {
Looper.prepare();
String cl_name, phoneNumber, password;
Clients cilents = new Clients();
cl_name = et_name.getText().toString();
phoneNumber = et_phone.getText().toString();
password = et_pwd.getText().toString();
if (validate(cl_name,phoneNumber ,password)) {
Intent intent = new Intent();
Bundle b = new Bundle();
Userinfo user = new Userinfo();
user.setUsername(cl_name);
user.setPhone(phoneNumber);
user.setPassword(password);
int i = cilents.addUser(user);
if(i>0){
b.putString("name", cl_name);
b.putString("phoneNumber", phoneNumber);
b.putString("password", password);
intent.setClass(Zc_login.this, Cl_page.class);
intent.putExtras(b);// 然后用intent进行传下去,传到Cl_page.java
startActivity(intent);
}else{/////////////////////////////////////最终程序就执行这,我想着是不是我在这里面写错了,还请为帮忙看看。