axis2 generates a client program through wsdl and calls it locally




2. Installation configuration
Extract axis2-1.6.2-bin.zip to the local directory D:\axis2-1.6.2 and

set environment variables. [Note: The java environment variable needs to be configured on the premise]
AXIS2_HOME set the value D:\axis2-1.6.2
Path Add the value %AXIS2_HOME%\bin


Enter cmd in the src directory of the project to pop up a command dialog box and output the following command line


in theGenerate code to call WebService:
%AXIS2_HOME%\bin\wsdl2java -uri http://localhost:8080/axis2/services/SimpleService?wsdl -p client -s -o stub



The -url parameter specifies the path of the wsdl file, you can It is a local path or a network path. The -p parameter specifies the package name of the generated Java class, and the -o parameter specifies the root directory where the generated series of files are saved.

After executing the above command, the reader will find that there is an additional stub directory in the current directory, and a SimpleServiceStub.java file can be found in the ."stub"src"client directory. This file calls the WebService in a complex way. Use this class directly, the code is as follows:
package client;
import javax.xml.namespace.QName;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
public class StubClient
{
public static void main(String[] args) throws Exception
{
SimpleServiceStub stub = new SimpleServiceStub();
SimpleServiceStub.GetGreeting gg = new SimpleServiceStub.GetGreeting();
gg.setName("Bill");
System.out.println( stub.getGreeting(gg).get_return());
System.out.println(stub.getPrice().get_return());
}
}

     The above code greatly simplifies the steps of calling the WebService and makes the code more concise. But it should be noted that the Stub class

generated encapsulates the parameters of the WebService method in the corresponding class, and the class name is the method name. For example, the parameters of the getGreeting method are encapsulated in the GetGreeting class. To call the getGreeting method, you must first create an object instance of the GetGreeting class. The generated stub file is in the same directory as the .aar file generated using services.xml.


This article is reproduced from: http://blog.sina.com.cn/s/blog_4f925fc30102dsvl.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326739610&siteId=291194637