Directly construct a soap package to call Web Service

Source: Internet
Author: User
Tags soapui

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.