一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

J2me访问dotnetwerbservice

时间:2022-07-02 17:43:21 编辑:袖梨 来源:一聚教程网

J2me访问dotnetwerbservice[分享]
Post by: chinapeople @ 2003-9-21 12:51:55
1.思路:使用j2me中本身自带的HttpConnection访问webservice,调用http://localhost/RoadWebService/RoadWS.asmx/中的方法WebServiceTest,参数为param。如下:
private void connect() {
HttpConnection hc = null;
//InputStream in = null;
DataInputStream in = null;
String s="";
String url = "http://localhost/RoadWebService/RoadWS.asmx/WebServiceTest?param="+inputTextField.getString();
try {
hc = (HttpConnection)Connector.open(url);
int ch;
in = hc.openDataInputStream();
while((ch=in.read())!=-1){
s=s+(char)ch;
}
//String s = in.readUTF();
in.close();
hc.close();
mMessageItem.setText(s);
}
catch (IOException ioe) {
mMessageItem.setText(ioe.toString());
}
// mDisplay.setCurrent(mMainform);
String [] items;
//此处是对的到的字符串S进行XML解析。
items = parseUsingkXML( s );
mDisplay.setCurrent( new ItemList( items ) );
}
这时候的到的字符串流是XML格式的,如下: hello zl
使用第三方的CLDC

热门栏目