@WebService public class HelloWorld { @WebMethod public String sayHello(String name) { return "Hello, " + name; } public static void main(String[] args) { String url = "http://localhost:8080/hello"; Endpoint.publish(url, new HelloWorld()); } } public class HelloWorldClient { public static void main(String[] args) { String url = "http://localhost:8080/hello"; QName qname = new QName("http://webservice.example.com/", "HelloWorldService"); Service service = Service.create(new URL(url + "?wsdl"), qname); HelloWorld hello = service.getPort(HelloWorld.class); System.out.println(hello.sayHello("Alice")); } } <servlet> <servlet-name>JAX-WS Servlet</servlet-name> <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class> <init-param> <param-name>javax.ws.rs.Application</param-name> <param-value>com.example.MyApplication</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>JAX-WS Servlet</servlet-name> <url-pattern>/hello</url-pattern> </servlet-mapping> <dependencies> <dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-rt</artifactId> <version>2.3.3</version> </dependency> </dependencies>


上一篇:
下一篇:
切换中文