Java Call WebService interface complete source code

Source: Internet
Author: User
Tags wsdl

The webservice provided by the other side is written in C #, and I can use this scheme for Java or C # (pro-Test) WebService. The steps are as follows:
1, create a common Java project, on the project right-new–other–web service Client–next, enter the WebService address in the box, for example: http://10.10.10.60:7000/srv_ WAIPAIITEM/WS/WP?WSDL (after the address is entered, you need to wait two seconds for next to click)

2, enter the correct WebService address, the way after the completion of the project will be under the SRC production of similar directory files:

The shortest class name is usually the name of the file you need.
3. The jar package that needs to be added is as follows: Jar package (free points): http://download.csdn.net/detail/zl544434558/8561227

4. The main method of the test code:

import org. Apache. CXF. Jaxws. Jaxwsproxyfactorybean;Importcom. ciming. Waipaiitem. WS. Waipairecordws;public class Testwebserviceclient {public static void main (string[] args) throws Exception {Jaxwsproxyfactorybean fact Ory = new Jaxwsproxyfactorybean ();Register WebService Interface Factory. Setserviceclass(Waipairecordws. Class);Set WebService address String url ="HTTP://10.10.10.61:7001/SRV_WAIPAIITEM/WS/WP?WSDL";Factory. Setaddress(URL);Waipairecordws record = (WAIPAIRECORDWS) factory. Create();Interface provides a method named Getdeliverysinglestring jsonstring = Record. Getdeliverysingle("ADK","Adkpwd","003300114112150914","Hz2_2");System. out. println(jsonstring);System. out. println("Successful Execution");}}

But if you run directly you will report a similar error like this:

ExceptioninchThread"Main"Javax. XML. WS. Webserviceexception: Could not find wsdl:binding operation info for Web method getdeliverysingle. at org. Apache. CXF. Jaxws. Jaxwsclientproxy. Invoke(Jaxwsclientproxy. Java:123) atcom. Sun. Proxy. $Proxy 17. Getdeliverysingle(Unknown Source) atcom. Evan. WebService. Test. Testwebserviceclient. Main(testwebserviceclient. Java: +)

The solution to this error is to add @webservice annotations to the interface of the generated file. For example, this project only needs to add @webservice to the Waipairecordws interface.

Java has now been able to invoke the remote webservice normally. and is as convenient as calling local methods. The entire demo:http://download.csdn.net/detail/zl544434558/8561301 of the project

Java Call WebService interface complete source code

Related Article

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.