11. generate code using tools

Source: Internet
Author: User

1. Use the WSDL2java tool class provided by Axis to generate code. The command is as follows:

C: \ SoftWare \ tomcat-5.0.28 \ tomcat-5.0.28 \ webapps \ AxisWebService \ WEB-INF> java-Djava. ext. dirs = lib org. apache. axis. wsdl. WSDL2Java-s http: // localhost: 8080/AxisWebService/services/HelloWorldWSDD? Wsdl-o c :\

-S is used to set the path url of the wsdl and the wsdl file on the current physical hard disk (you can save the xml file of the wsdl on the page as a try, which is also possible)

-O is the output directory of the converted file.

The above command will produce the server implementation code and the client call code. The code file is as follows:

 

Deploy and undeploy are wsdd files for publishing and uninstalling WebService.

HelloWorldWSDD is a server-side code interface file that inherits the Remote interface and defines the getAge and sayHello methods.

HelloWorldWSDDService is the interface for obtaining the current Service instance

HelloWorldWSDDServiceLocator implements the HelloWorldWSDDService interface, which is useful when the client calls the current WebService.

HelloWorldWSDDSoapBindingImpl current WebService Interface Implementation of HelloWorldWSDD, You need to implement your own business method

HelloWorldWSDDSoapBindingStub at the end of the Stub will know, this can complete the implementation of the client, it can be used to call the WebService Method

 

The following code is generated using WSDL2Java to call WebService. Note that you must use the doscommand to publish the above service through deploy. wsdd. The following is the call code:

 

Code

 Package localhost. AxisWebService. services. HelloWorldWSDD. clientimpl;

Import java.net. MalformedURLException;
Import java.net. URL;
Import java. rmi. RemoteException;
Import javax. xml. rpc. ServiceException;
Import localhost. AxisWebService. services. HelloWorldWSDD. HelloWorldWSDDServiceLocator;
Import localhost. AxisWebService. services. HelloWorldWSDD. HelloWorldWSDDSoapBindingStub;

Public class Client {
Public static void main (String [] args) throws ServiceException, RemoteException, MalformedURLException {
String target = "http: // localhost: 8080/AxisWebService/services/HelloWorldWSDD ";
HelloWorldWSDDServiceLocator service = new HelloWorldWSDDServiceLocator ();
HelloWorldWSDDSoapBindingStub stub = new HelloWorldWSDDSoapBindingStub (new URL (target), service );

System. out. println (stub. getAge (22 ));
System. out. println (stub. getName ("Zhang San "));
}
}

 

 

It is relatively simple to use the automatically generated code to call the client, if your WebService implementation version is JAX-WS2.0, you can use MyEclipse WebService plug-in tool to help us produce code, such as: axis2 can, next time, we will introduce the usage of Axis2.x.

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.