http://blog.csdn.net/flightme/article/details/6977191
. Create a WebService project.
2. Create a plain Java Class View plaincopy to Clipboard
- Package com.hmw.jaxws;
- /**
- * Test <br> for WebService service
- * <b> Note:</b> The class must have a parameterless construction method, or you cannot use the MyEclipse Wizard to create a JAX-WS WebService Server class for this class <br>
- * <b> Created Date </b>:2011-1-17
- * @author <a href= "Mailto:[email protected]" mce_href= "Mailto:[email protected]" > He Mingwang </a>
- */
- Public class Hellojaxws {
- public string SayHello (string userName) {
- return userName + "Hello, this is my first JAX-ws program. ";
- }
- public int Add (int i, int j) {
- return i + j;
- }
- }
[Java]View Plaincopy
- Package com.hmw.jaxws;
- /**
- * Test <br> for WebService service
- * <b> Note:</b> The class must have a parameterless construction method, or you cannot use the MyEclipse Wizard to create a JAX-WS WebService Server class for this class <br>
- * <b> Created Date </b>:2011-1-17
- * @author <a href= "Mailto:[email protected]" mce_href= "Mailto:[email protected]" > He Mingwang </a>
- */
- Public class Hellojaxws {
- Public string SayHello (String userName) {
- return userName + "Hello, this is my first JAX-ws program. ";
- }
- public int Add (int i, int j) {
- return i + j;
- }
- }
3. Create a WebService server
The source code for Hellojaxwsdelegate.java is as follows:
View Plaincopy to Clipboard
- Package com.hmw.jaxws;
- @javax. Jws.webservice (targetnamespace = "http://jaxws.hmw.com/", ServiceName ="Hellojaxwsservice", PortName = "Hellojaxwsport", wsdllocation = "web-inf/wsdl/hellojaxwsservice.wsdl")
- Public class Hellojaxwsdelegate {
- Com.hmw.jaxws.HelloJaxws Hellojaxws = new Com.hmw.jaxws.HelloJaxws ();
- public string SayHello (string userName) {
- Return Hellojaxws.sayhello (UserName);
- }
- public int Add (int i, int j) {
- Return Hellojaxws.add (i, j);
- }
- }
[Java]View Plaincopy
- Package com.hmw.jaxws;
- @javax. Jws.webservice (targetnamespace = "http://jaxws.hmw.com/", ServiceName = "Hellojaxwsservice", PortName = "Hellojaxwsport", wsdllocation = "web-inf/wsdl/hellojaxwsservice.wsdl")
- Public class Hellojaxwsdelegate {
- Com.hmw.jaxws.HelloJaxws Hellojaxws = new Com.hmw.jaxws.HelloJaxws ();
- Public string SayHello (String userName) {
- return Hellojaxws.sayhello (userName);
- }
- public int Add (int i, int j) {
- return Hellojaxws.add (i, j);
- }
- }
4. Import the associated jar package and send the project to Tomcat to launch Tomcat.
The directory structure for the entire project is as follows:
5. Create a WebService client project (plain Java project).
6. Create a client-related call class
7. Create a test class
The code for the test class Clienttest.java is as follows:
View Plaincopy to Clipboard
- Package com.hmw.client.jaxws;
- Public class Clienttest {
- Public static void Main (string[] args) {
- Hellojaxwsdelegate service = new Hellojaxwsservice (). Gethellojaxwsport ();
- System.out.println (Service.sayhello ("Hemingwang"));
- System.out.println ("result is:" + service.add (1, 2));
- }
- }
[Java]View Plaincopy
- Package com.hmw.client.jaxws;
- Public class Clienttest {
- public static void Main (string[] args) {
- Hellojaxwsdelegate service = new Hellojaxwsservice (). Gethellojaxwsport ();
- System.out.println (Service.sayhello ("Hemingwang"));
- System.out.println ("result is:" + service.add (1, 2));
- }
- }
The directory structure for the entire project is as follows:
8. Run the test class
The results of the operation are as follows:
MyEclipse Development WebService Tutorial (GO)