What is the difference between Web Service and common Java Servlet? In my opinion, Web Service only uses the soap package to construct a request, and then calls the package,
However, WSDL only teaches you how to build a soap package. The followingCodeDemonstrate how to build a soap package and directly call web service.
Code
String data = " <Soapenv: envelope xmlns: soapenv = 'HTTP: // schemas.xmlsoap.org/soap/envelope/'xmlns: IFAC = 'HTTP: // iface.motor.com/'> " +
" <Soapenv: Header/> " +
" <Soapenv: Body> " +
" <IFAC: getstateinfo> " +
" <Carno> AA </carno> " +
" <Color> ad </color> " +
" <Carframe> DD </carframe> " +
" </IFAC: getstateinfo> " +
" </Soapenv: Body> " +
" </Soapenv: envelope> " ;
// Send data
URL = New URL ( Http: // localhost/svc/motorservice );
Urlconnection Conn = URL. openconnection ();
Conn. setdooutput ( True );
Outputstreamwriter WR = New Outputstreamwriter (conn. getoutputstream ());
Wr. Write (data );
Wr. Flush ();
// Get the response
Bufferedreader Rd = New Bufferedreader ( New Inputstreamreader (conn. getinputstream ()));
String line;
While (Line = Rd. Readline ()) ! = Null ){
System. Out. println (line );
}
Wr. Close ();
Rd. Close ();
The above Code shows that we have built a soap package and sent the package to the Web service address.
We can observe the returned results. We can see that the returned results are also a soap package.
To obtain the SOAP request package conveniently, we can use the soapui tool. Address: http://www.soapui.org/