Create a service-side
First, File–>new–>project
Second, click Next and enter the server name, click Finish, generate the directory as follows
Third, right-click in the Helloworld.java file, select WebServices, and then select Generate Wsdl from Java Code, determine
Clicking OK will automatically generate helloworld.wsdl for us, draw the Red line note
Four, configure Tomcat, there is not much to say, mainly in the configuration of Tomcat after the need to join Axis library
Click Fix in the lower right corner, restart Tomcat, enter in the browser: http://localhost:8080/services, the following message appears, representing the successful deployment.
Click HelloWorld (WSDL) to see the corresponding information
Now that the server-side web Service is created, I'll continue to explain how to create the client's web service!
To create a client:
First, File–>new–>project
Enter the client project name, finish, project creation will automatically jump out of the following interface, manually can right-click the project –>webservice–>generate Java Code from Wsdl can be
Then click on your project name email to select the following
Import the WSDL file for the server you created before
Clicking Ok,idea will help us generate the corresponding code, the test class is as follows:
Package Example;import com. Helloworldservicelocator;import Com.sun.corba.se.spi.activation.activator;public class HelloWorldClient { public static void Main (string[] argv) { try { Helloworldservicelocator locator = new Helloworldservicelocator () ; Activator service = Locator.get (); IF authorization is required //((helloworldsoapbindingstub) service). Setusername ("User3"); ((helloworldsoapbindingstub) service). SetPassword ("Pass3"); Invoke Business Method Service.businessmethod (); } catch (Javax.xml.rpc.ServiceException ex) { Ex.printstacktrace (); } catch (Java.rmi.RemoteException ex) { ex.printstacktrace ();}} }
At this point, there will be an error, Helloworldservicelocator class is because there is no guide package according to Alt+enter Guide package, the following in some code modification
Activator service = Locator.get (); Service.businessmethod ();
Change into
Helloworld_porttype service = Locator.gethelloworld ();
String str = service.sayhelloworldfrom ("Sushan"); System.out.println (str);
Run the client at this time the main method will also error, the reason for the error is that there is no junit jar package, my practice is to join MAVEN
Run the client at this time the main method will also error, the reason for the error is that there is no junit jar package, my practice is to join MAVEN
Specific steps:
1. Now the project creates a new pom.xml (preferably pasted from an existing MAVEN project)
2. Close item Delete Recent open history reopen this project
3. Show if the stale MAVEN project Click Yes
Then join the dependency in the POM
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency>
Get the final result for
Use idea to create a detailed process for Web service server and client