webservice接口开发(一)

服务端(java project):server

Hello.java

package com.xfsy.ws;

import javax.jws.WebMethod;

import javax.jws.WebService;

@WebService

public interface Hello {

          @WebMethod

           public String sayHello(String name);

}

HelloImpl.java

package com.xfsy.ws;

import javax.jws.WebService;

@WebService

public class HelloImpl implements Hello {

          @Override

          public String sayHello(String name) {

                     return "Say hello " + name;

          }

}

Test.java

package com.xfsy.ws;

import javax.xml.ws.Endpoint;

public class Test {

         public static void main(String[] args) {

                   String address = "http://192.168.1.3:9090/web";

                   Endpoint.publish(address , new HelloImpl());

         }

}

客户端端(java project):client

cmd进入clent->src目录:

E:\Workspace\Jee\client\src>

输入如下命令:wsimport -keep http://192.168.1.3:9090/web?wsdl

Test.java

package com.xfsy.ws.test;

import com.xfsy.ws.HelloImpl;

import com.xfsy.ws.HelloImplService;

public class Test {

          public static void main(String[] args) {

                     HelloImplService factory = new HelloImplService();

                     HelloImpl helloWS = factory.getHelloImplPort();

                     String result = helloWS.sayHello("Tome");

                     System.out.println(result);

         }

}

你可能感兴趣的:(webservice接口开发(一))