Client asynchronous call of web service integrated with web engineering in JAX-WS

Source: Internet
Author: User

This article is in my previous article: "JAX-WS integration web service creation and publishing simple entry (1)" on the basis of, that is, the creation and release of the server.

When a client accesses the server, it needs to send messages to the server. There are two types: synchronous and asynchronous:

Synchronous call:One request is sent from the client to the server and server.InstantReturn a response.

Asynchronous call:After the client calls the server once, the server processes the transaction andNot immediate returnFor example, if you upload a MB file to the server, the client will not immediately receive a response when processing the received and parsed files. It will wait for a while and wait until the server completes processing, then, notify the client that "I have finished processing ".

Now, you can call the client asynchronously.

1. For simplicity, you only need to create a Java project. For example, I have created a Java project called client as the client.

2. Create an xml configuration file under the root directory of the client project, for example, binding. xml. The content is as follows:

<?xml version="1.0" encoding="UTF-8"?><bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" wsdlLocation="http://10.225.112.86:8888/myWS2/HelloService?wsdl"xmlns="http://java.sun.com/xml/ns/jaxws"><bindings node="wsdl:definitions"><enableAsyncMapping>true</enableAsyncMapping></bindings></bindings>

3. Dos enters the root directory of the client project and runs the following command:

It indicates that the client-side auxiliary code is successful, but it seems a lot better. Click the src directory and you will see it.

4. Compile a Java class to test asynchronous calls:

package leon.test;import javax.xml.ws.Response;import leon.ws.Hello;import leon.ws.HelloService;import leon.ws.SayHelloResponse;public class TestHelloAsyn {public static void main(String[] args) {HelloService service = new HelloService();Hello port = service.getHelloPort();Response<SayHelloResponse> resp = port.sayHelloAsync("LeonSU");while (!resp.isDone()) {System.out.println("not done. Hold on please...");}try {SayHelloResponse callNameResponse = resp.get();String message = callNameResponse.getReturn();System.out.println(message);} catch (Exception e) {e.printStackTrace();}}}

The client has been created. However, if you don't rush to run this class, an error will be reported. Look at the server, the server needs to introduce two jar package: saaj-api.jar, saaj-impl.jar, if there is no, hurry to introduce it. Then run the server. Then the testhelloasyn. Java of the client can be run:

OK.

 

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.