"Engineering" NOTE: No need to generate client code using Wsimport
"Httpclient.java"
ImportJava.io.ByteArrayOutputStream;Importjava.io.IOException;ImportJava.io.InputStream;Importjava.net.HttpURLConnection;ImportJava.net.URL; Public classHttpClient { Public Static voidMain (string[] args)throwsIOException {//Open an HTTP link//WebService AddressURL url =NewURL ("Http://127.0.0.1:12345/weather"); HttpURLConnection HttpURLConnection=(HttpURLConnection) url.openconnection (); //set POST request, post is uppercaseHttpurlconnection.setrequestmethod ("POST"); //content-type:text/xml; Charset=utf-8Httpurlconnection.setrequestproperty ("Content-type", "text/xml; Charset=utf-8 "); //set up requests and responsesHttpurlconnection.setdoinput (true); Httpurlconnection.setdooutput (true); String requeststring= RequestString ("Zhengzhou"); //Send SOAP protocolHttpurlconnection.getoutputstream (). Write (Requeststring.getbytes ()); //Receive response contentInputStream InputStream=Httpurlconnection.getinputstream (); Bytearrayoutputstream Bytearrayoutputstream=NewBytearrayoutputstream (); intLen=-1; byte[] B =New byte[1024]; //Write InputStream content to Bytearrayoutputstream while((len= inputstream.read (b, 0, 1024))!=-1) {Bytearrayoutputstream.write (b,0, Len); } //Get Response ContentString responsestring =bytearrayoutputstream.tostring (); System.out.println (responsestring); //parse the XML data for the response. //....Inputstream.close (); Bytearrayoutputstream.close (); } /**<?xml version= "1.0"?> <s:envelope xmlns:s= "http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <ns2:queryweather xmlns:ns2="http://server.weather.jaxws.Higgin.com/"> <arg0> zhengzhou </arg0> </ns2:queryWeather> </S:BODY&G T </S:Envelope>*/ //Content of the SOAP protocol, content of the request Private Staticstring requeststring (String cityname) {string xmlstring="<?xml version=\" 1.0\ "?>" + "<s:envelope xmlns:s=\" http://schemas.xmlsoap.org/soap/envelope/\ ">" + "<S:Body>" + "<ns2:queryweather xmlns:ns2=\" http://server.weather.jaxws.Hi Ggin.com/\ ">" + "<arg0>" +cityname+ "</arg0>" + "</ns2:queryweather& gt; "+" </S:Body> "+" </S:Envelope> "; returnxmlstring; }}
"Run Results"
(Note: To start the WebService service first)
(need to further parse out the data you need, using regular expressions)
09_HTTPCLIETN Testing the SOAP protocol