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