当前位置: 代码迷 >> J2ME >> webservice…解决方法
  详细解决方案

webservice…解决方法

热度:9422   发布时间:2013-02-25 21:33:48.0
webservice………………………………………………………………………………………………
java webservice如何传递参数和接收参数???
请直接上代码

------解决方案--------------------------------------------------------
package com.smart_home;

import java.io.IOException;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;


public class SHMIDlet extends MIDlet {

private Display display;
private TextField tfURL, tfUN, tfPW;
private Command cmdLogin, cmdExit;
private Form loginForm;

private String URL;
private String NAMESPACE;
private String SOAP_ACTION;
private String METHOD_NAME;
private SoapSerializationEnvelope envelope;
private SoapObject rpc;
private HttpTransportSE ht;

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}

protected void pauseApp() {
}

protected void startApp() throws MIDletStateChangeException {
display = Display.getDisplay(this);
loginFace();
display.setCurrent(loginForm);

}

private class LoginListener implements CommandListener{
public void commandAction(Command c, Displayable d) {
if (c == cmdLogin) {
Thread thread = new Thread(){
public void run() {
URL = "http://cjf780426.xicp.net:803/Demo/DEMO1/GBSvr.dll/soap/IGBSvr/";
NAMESPACE = "http://tempuri.org/";
METHOD_NAME = "GBlogin";
SOAP_ACTION = "urn:GBSvrIntf-IGBSvr#GBlogin";
String response = null;
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
rpc = new SoapObject(NAMESPACE, METHOD_NAME);
ht = new HttpTransportSE(URL);
rpc.addProperty("UserName", "9990520777");
rpc.addProperty("UserPWD", "123");
envelope.dotNet = true;
envelope.bodyOut = rpc;
envelope.setOutputSoapObject(rpc);
try {
ht.debug = true;
ht.call(SOAP_ACTION, envelope);
response = (String) envelope.getResponse();
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
System.out.println(response);
}
};
thread.start();
}
}
}

public void loginFace() {
loginForm = new Form("登陆");
tfURL = new TextField("地址:", "", 150, TextField.ANY);
tfUN = new TextField("用户名:", "", 20, TextField.ANY);
tfPW = new TextField("密码:", "", 20, TextField.ANY);
cmdLogin = new Command("登陆", Command.OK, 1);
cmdExit = new Command("退出", Command.EXIT, 1);
loginForm.append(tfURL);
loginForm.append(tfUN);
loginForm.append(tfPW);
loginForm.addCommand(cmdLogin);
loginForm.addCommand(cmdExit);
loginForm.setCommandListener(new LoginListener());
}

}
  相关解决方案