Java Call WebService

Source: Internet
Author: User

To invoke the WebService step:

1. Generate client code based on the WSDL address obtained

2. Copy the generated. java file as used in the project

Describes two ways to generate client code:

1. Using the tools provided by the JDK Wsimport.exe (located under Java_home/bin)

①. Open cmd where code generation is required

②. Execute wsimport-s. WSDL address (where. Represents the generated location as the current directory)

Example: Wsimport-s. http://webservice.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl

2. Using CXF (Apache-cxf-2.6.2.zip)

①. Adding CXF to environment variables

Verify:

Operation win+r---> cmd---> Enter---"Wsdl2java-v

Results show Wsdl2java-apache CXF 2.6.2

Prove the configuration is successful

②. Using Wsdl2java.exe

wsdl2java-d src-client http://webservice.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl

3. Troubleshoot errors encountered during build:[ERROR] undefined element declaration ' S:schema '

①. Save the WSDL Web page locally (note: You can only save it with the browser's own "Web page Save As ...")--Change the suffix name to. wsdl

②. Open the file with an editor and the

<s:element ref= "S:schema"/>
<s:any/>

Place to replace

<s:any minoccurs= "2" maxoccurs= "2"/>

③. Generating client code with a modified WSDL file

4. Call the WebService service based on the information provided by the. asmx address provided by Webservcice.

Java Call WebService

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.