Recent projects useful to WebService, so studied, but about IntelliJ development WebService article very little, or many years ago, so study, write this blog post. Pure record, sharing, the middle of the wrong place, please correct me, the following start.
First of all, the development of the server side of the WebService, do not need any other, the JDK can be done, as long as the class labeled @webservice, and on the method, labeled @webmethod method, you can think he is a WebService.
Now, let's show my directory structure:
The server-side code under the server package is the client code under the clients package.
Here's a look at the service-side code:
Helloworldws.java
1 Package server; 2 3 /* * 4 * Created by Lin_yang on 2014/12/16. 5 */ 6 Public Interface Helloworldws {7 Public string SayHello (string name); 8 }
This is an interface. (Of course you can not have this interface, the effect is the same)
Helloworldimpl.java
Package Server;import javax.jws.webmethod;import javax.jws.webservice;/** * Created by Lin_yang on 2014/12/16. */@WebServicepublic class Helloworldimpl implements Helloworldws { @WebMethod @Override Public String SayHello (string name) { string str= "welcome you:" +name; System.out.println (str); return str; }}
Note the above two comments @webservice and @WebMethod
We can publish this webservice.
Publish.java
Package Server;import javax.xml.ws.endpoint;/** * Created by Lin_yang on 2014/12/16. */public class Publish {public static void Main (String args[]) { Object implementor = new Helloworldimpl (); String address = "Http://localhost:8989/HelloWorld"; Address Endpoint.publish posted to : (address, implementor); System.out.println ("Publish Success");} }
The client's code is simple, and it's not great length.
The following focuses on the client code creation process.
INTELLIJ14 has built-in WebService client code implementations, and he is using Jax-ws. Nonsense not much to say.
Java code from WSDL in the Intellj tool-->webservices-->generate (a look at the Java codes generated from the WSDL document)
This should be followed by a popup box.
First, the WEB service WSDL URL is the location that indicates the WSDL document, where the address corresponds to the address published by the server. He can also find this WSDL document from the Web, or from a local source.
The format is this: file:/c:/crmloymembercreateworkflow.wsdl The address of the specified document.
This code will be generated in the client package as per the configuration
Below, we can access the webservice of the server based on these generated code.
Test/client.java
Packageclient.test;Importclient. Helloworldimpl;Importclient. Helloworldimplservice;/*** Created by Lin_yang on 2014/12/16.*/ Public classClient { Public Static voidMain (String args[]) {helloworldimplservice Helloworldimplservice=NewHelloworldimplservice (); Helloworldimpl HelloWorld=Helloworldimplservice.gethelloworldimplport (); String Returnstr= Helloworld.sayhello ("The Prophet's Sleep")); System.out.println (RETURNSTR); }}
Service-side display
Client display:
Hope can give us some inspiration.
IntelliJ Development WebService