The company recently let the interface based on other companies to write its own interface, the interface for other companies equivalent to the client, but for their own company to invoke the program, is equivalent to the service side.
Idle to have nothing to do, summarize under.
Start with the Java-brought service first
Jax-ws (Java API XML WebService) JAVAAPI-based WebService implementation
The tool used is MyEclipse
The first is the service side
1. New WebProject Jax-wsserver
2. New packages and classes such as
Since it's an introductory example, the simpler the better, the more important the process
Imservice.java content is as follows
Package com.jax.server;
Public interface Imyservice {
public int Add (int a,int b);
public int minus (int a,int b);
}
Myserviceimpl.java content is as follows
Package com.jax.server;
public class Myserviceimpl implements Imyservice {
public int Add (int a, int b) {
TODO auto-generated Method Stub
return a+b;
}
public int minus (int a, int b) {
TODO auto-generated Method Stub
return a-B;
}
}
The above basic preparation work is completed, the following is the application of myeclipse concrete steps.
1 Right-click src-new Others, select Web Service
2. Click Next, choose to create from the Java class in Jax-ws mode,
3. Click Next and select the class you want to use, which is the myserviceimpl we just created, if the entity class.
Choose to generate the WSDL in the project,
Click Finish.
4. Right-click the project, select Properties, select "Java Build Path" and select "Libraries",
5. Click Add Libraries, select MyEclipse Libraries, such as:
6. Click Next, select Jax-WS,
7. Click Finish, such as:
8. Click OK, engineering structure such as:
9. At this point, the server-side program has been generated, deployed to Tomcat, launched Tomcat, access to address http://localhost:8080/ProjectWS/WSServerPort?wsdl, such as
The WSDL page appears as shown, indicating that the local service has been started and can be accessed.
The external address is http://localhost:8080/jax-wsServer/MyServiceImplPort?wsdl.
namespace targetnamespace= "http://server.jax.com/"
Service name PortType name= "Myserviceimpldelegate"
Provides two ways to add and minus
This complete WebService server is configured and released.
Below is how the JAX-WS server is generated and invoked.
1. Can create a new project (because it is a test, for the sake of trouble, here and the server with a project), right-click SRC, select the Web Service Client,
2. Select the Web Service Client and click Next, such as:
3. Click Next to specify the path of the webservice to be accessed, the address we just visited, the package that specifies the client file
4. Click Next, such as:
5.Finish completed, the client file generation completed, the structure is as follows:
6. Write the test class TestClient, the code is as follows
package com.jax.client;
public class TestClient {
public static void Main (String []arg) {
//service specific class, inherits service class
Myserviceimplservice service=new Myserviceimplservice ();
//interface of the service, get
Myserviceimpldelegate Se=service.getport (Myserviceimpldelegate.class);
//call methods through the interface of the service
int Add=se.add ( 34, 23);
int Minus=se.minus (34, 23);
System.out.println ("34+23=" +add);
System.out.println ("34-23=" +minus);
}
}
7. The results of the operation are as follows:
To this complete on the JAX-WS service side, the client's generation call the entire process is complete, with everyone to learn, mutual encouragement.
Follow-up will also have a detailed process of CXF.
JAX-WS server-side generation and client invocation instances