⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 soapdemo.java

📁 里面包含ksoap2J2ME类库和ksoap2的源码
💻 JAVA
字号:
package net.wessendorf.j2me;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.TextBox;import javax.microedition.lcdui.TextField;import javax.microedition.midlet.MIDlet;import org.ksoap2.SoapEnvelope;import org.ksoap2.SoapFault;import org.ksoap2.serialization.SoapObject;import org.ksoap2.serialization.SoapSerializationEnvelope;import org.ksoap2.transport.HttpTransport;public class SoapDemo extends MIDlet implements CommandListener{        private Command exitCommand;    private Display display;        Form mainForm = new Form ("Hello World WebService");    TextField nameField = new TextField ("Your name","",456,TextField.ANY);    Command getCommand = new Command ("send", Command.SCREEN, 1);    public SoapDemo () {    	mainForm.append (nameField);    	mainForm.addCommand (getCommand);    	mainForm.setCommandListener (this);    }        public void startApp() {        display = Display.getDisplay (this);        display.setCurrent (mainForm);  }        public void pauseApp() {    }        public void destroyApp(boolean unconditional) {    }        public void commandAction(Command c, Displayable s) {        if (c == getCommand) {         	final TextBox t = new TextBox("", "", 256, 0);                    	Thread thr = new Thread(){        	    public void run() {            	try {                             SoapObject client = new                SoapObject("","getObject");                client.addProperty("name",nameField.getString());                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);                envelope.bodyOut = client;                HttpTransport ht = new                HttpTransport("http://localhost:8080/axis/services/AxisService");                ht.call("", envelope);                SoapObject ret = new SoapObject("http://ws.wessendorf.net","CustomObject");                ret =(SoapObject)envelope.getResult();                t.setString(ret.getProperty(0).toString());            }            catch ( SoapFault sf){                String faultString = "Code: " + sf.faultcode + "\nString: " + sf.faultstring;                t.setString(faultString);            }            catch ( Exception e){                e.printStackTrace();                t.setString(e.getMessage());            }           	}};           	thr.start();            display.setCurrent(t);        }        else{            destroyApp(false);            notifyDestroyed();        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -