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