Access dotnetwerbservice through j2-based [sharing]
Post by: chinapeople @ 2003-9-21 12:51:55
1. Train of Thought: Use the HttpConnection that comes with j2s to access webservice and call the WebServiceTest method in http: // localhost/RoadWebService/RoadWS. asmx/. The parameter is param. As follows:
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;
// XML parsing is performed on the string S.
Items = parseUsingkXML (s );
MDisplay. setCurrent (new ItemList (items ));
}
At this time, the string stream is in XML format, as follows: hello zl
Use third-party CLDC