WebService debugging Tools mentioned earlier, if you are interested in writing test code, it is very good ah.
I also think so, there are ideas may wish to try Oh. Then, my program mainly uses the HttpURLConnection class, first splicing conforms to the SOAP protocol XML string information, then establishes the connection with the WebService server, sends the HTTP request, receives the return information to print out. Process and SOAPUI Debugging tools of the same, the following provides the code of the test program, you can refer to.
Import Java.io.BufferedReader;
Import Java.io.InputStream;
Import Java.io.InputStreamReader;
Import Java.io.OutputStream;
Import java.net.HttpURLConnection;
Import Java.net.URL; public class HTTP {public String httpget (string httpurl) {string reqmsg = ' <soapenv:envelope xmlns:soapenv=\ ' http ://www.w3.org/2003/05/soap-envelope\ ">" + "<soapenv:Header>" + "<ns1:username xmlns:ns1=\" Http://servi Ce.webservice.ultrapower.com.cn\ "soapenv:mustunderstand=\" false\ ">username</ns1:Username>" + "<NS1: Password xmlns:ns1=\ "http://service.webservice.ultrapower.com.cn\" soapenv:mustunderstand=\ "false\" >USERPW </ns1:Password> "+" </soapenv:Header> "+" <soapenv:Body> "+" <ns1:sendxml xmlns:ns1=\ "htt P://service.webservice.ultrapower.com.cn\ ">" + "<ns1:requestXml>" + "<?xml version=\" 1.0\ "encoding=\" Utf-8\ "?>" + "<ReadWhiteList>" + "<srcDeviceType>32</srcDeviceType>" + "≪srcdeviceid>321101</srcdeviceid> "+" <Cmd>0</Cmd> "+" </ReadWhiteList> "+" < /ns1:requestxml> "+" <ns1:busiKey>11</ns1:busiKey> "+" </ns1:SendXML> "+" </soapen
V:body> "+" </soapenv:Envelope> ";
URL url = null;
HttpURLConnection httpurlconn= null;
StringBuffer datastring = new StringBuffer ("");
The string temp = new string ();
try{System.out.println (Httpurl);
url = new URL (httpurl);
Httpurlconn= (HttpURLConnection) url.openconnection ();
Httpurlconn.setdooutput (TRUE);
Httpurlconn.setrequestmethod ("POST"); Httpurlconn.setconnecttimeout (300*1000);//300s timeout Httpurlconn.setrequestproperty ("User-agent", "Apache-HttpClien
t/4.1.1 (Java 1.5) ");
Httpurlconn.setrequestproperty ("Content-type", "application/soap+xml;charset=utf-8;action=\" urn:SendXML\ ")"; OutputStream out = HTTPURlconn.getoutputstream ();
Out.write (Reqmsg.tostring (). GetBytes ());
Httpurlconn.connect ();
InputStream in =httpurlconn.getinputstream ();
BufferedReader bd = new BufferedReader (new InputStreamReader (in));
while ((Temp=bd.readline ())!=null) {datastring.append (New String (Temp.getbytes ()));
} in.close ();
Bd.close ();
catch (Exception e) {e.printstacktrace ();
} finally{if (httpurlconn!=null) {httpurlconn.disconnect ();
} try{System.out.println (New String (Datastring.tostring (). GetBytes ("GBK"), "Utf-8"));
}catch (Exception e) {e.printstacktrace ();
return datastring.tostring ();
public static void Main (string[] arg {http PM = new http ();
Pm.httpget ("http://132.xx.xxx.xx:8080/xxx//xxx?wsdl");
}
}
There is no feeling of stitching this XML, a little bit complicated. This WebService server soaphead security mechanism, no way, the client asked to do so. Then I'll introduce the WebService server with Soaphead security mechanism.
Reprint please explain from whilejolly:http://blog.csdn.net/seedingly/article/details/39054609