JAX-WS 2: creating a client

Source: Internet
Author: User
Tags webservice annotation wsdl
JAX-WS 2: creating a client
    Blog type: 

  • JAX-WS
  • Java-related
 

The previous section describes how to create a server based on the JAX-WS API, This section describes how to create a client to call the WebService Service.

 

Creating a Client is also quite simple, but you need to know a few things:

 

1. wsdl file path

 

You need to read the wsdl definition file provided by the server. For example:

Java code
  1. URL url = new URL ("http: // localhost: 8088/calculate? Wsdl ");

 

2. QName of the Service to be called

 

Multiple services may be defined in a wsdl, so you need to specify the Service name to be called. For example:

Java code
  1. QName qName = new QName ("http: // test /",
  2. "CalculatorImplService ");

 

 

3. Create a Service

 

With the qname of the wsdl service, you can create the corresponding service object:

Java code
  1. Service service = Service. create (url, qName );

 

4. Get the corresponding Port

 

With the Service, you can obtain a Port in the Service, for example:

Java code
  1. Calculator port = service. getPort (Calculator. class );

Here are some notes:

  1.  

    1. Parameter of the getPort () method: This method always requires the serviceEndpointInterface class object to be added to the serviceEndpointInterface class @ WebService annotation.
    2. The targetNamespace of serviceEndpointInterface must match the namespace of the corresponding portType. The default value is "http: // package name/". If necessary, You need to define the targetNamespace attribute of @ WebService to change it.
    3. The name of serviceEndpointInterface always needs to match the name of the PortType to be called. The default type is the class name. If necessary, you must specify the @ WebService name attribute to change it.
    4. The serviceEndpointInterface must have a method definition corresponding to the operation to be called.
    5. Last call Method

5. Call Method

 

After obtaining the corresponding information, you can call the desired method, for example:

Java code
  1. System. out. println (port. add (1, 2 ));

 

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.