Use eclipse to build webservice service and client

A web service is a platform-independent, low-coupling, self-contained, programmable web-based application that can be described, published, discovered, coordinated using the open XML (a subset of the standard Universal Markup Language) standard And configure these applications for developing distributed interoperable applications.

Web Service technology enables different applications running on different machines to exchange data or integrate with each other without resorting to additional, specialized third-party software or hardware. Applications implemented according to the Web Service specification can exchange data with each other regardless of the language, platform or internal protocol they use. Web Service is a self-describing, self-contained, available network module that can perform specific business functions. Web Services are also easy to deploy because they are based on some conventional industry standards and some existing technologies, such as XML, HTTP, a subset of the standard Universal Markup Language. Web Services reduce the cost of application interfaces. Web Services provide a common mechanism for the integration of business processes across an enterprise or even among multiple organizations.

That is to say, through webservice, we can connect the communication between C#, java, etc.

Below, I use eclipse to create a simple Webservice service:

First, we create a web project in eclipse, new->Dynamic Web Project, here I named it helloService


Next, we first build a method that needs to be exposed to the outside world,

[java]  view plain  copy
  1. package service;  
  2.   
  3. publicclass HelloService {   
  4.     public String say(String name) throws InterruptedException{  
  5.         return"hello "+name;   
  6.     }  
  7. }  


Then, right click on the project, new -> other->web services->webservice


Select the implementation that needs to be exposed, service.HelloService, and choose Publish


We publish it through tomcat, just start it directly. Commonly used frameworks are cxf, axis, axis2, etc., axis is selected here

After publishing, we can open its wsdl by opening the webpage and entering the address: http://localhost:8280/helloService/services/HelloService?wsdl

The previous address can be seen under helloService\WebContent\wsdl\HelloService.wsdl,



Now the server has been established.

Next, we need to use the client to connect to this Webservice service,

Create a new java project (both possible)


Then create a new Webservice client,

Enter the wsdl address and finish


Then you can see the Webservice java class in the directory,


We create a new test to test the following

[java]  view plain  copy
  1. package test;  
  2.   
  3. import java.rmi.RemoteException;  
  4.   
  5. import service.HelloService;  
  6. import service.HelloServiceProxy;  
  7.   
  8. publicclass Test {   
  9.   
  10.     publicstaticvoid main(String[] args) throws RemoteException {    
  11.         HelloServiceProxy helloPxy = new HelloServiceProxy();  
  12.         HelloService service = helloPxy.getHelloService();  
  13.         String res = service.say("yyf");  
  14.         System.out.println(res);  
  15.     }  
  16.   
  17. }  


Getting started with Webservices is over.

Client Timeout Disconnect Settings:

HelloServiceSoapBindingStub->

[java]  view plain  copy
  1. protected org.apache.axis.client.Call createCall() throws java.rmi.RemoteException {  
  2.          _call.setTimeout( 1000 ); //Set the timeout  



Reprinted: https://blog.csdn.net/qq_18860653/article/details/53758555

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324850500&siteId=291194637