<dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-metadata</artifactId> <version>1.7.10</version> </dependency> package com.example; import javax.jws.WebMethod; import javax.jws.WebService; @WebService public class HelloWorldService { @WebMethod public String sayHello() { return "Hello, World!"; } } package com.example; import org.apache.axis2.jaxws.description.DescriptionFactory; import org.apache.axis2.jaxws.description.EndpointDescription; import org.apache.axis2.jaxws.spi.ServiceDelegate; public class WebServicesPublisher { public static void main(String[] args) { HelloWorldService service = new HelloWorldService(); ServiceDelegate serviceDelegate = new ServiceDelegate(); EndpointDescription endpointDescription = DescriptionFactory.createEndpointDescription(service.getClass(), serviceDelegate); String address = "http://localhost:8080/hello"; endpointDescription.setAddress(address); org.apache.axis2.jaxws.spi.Provider.provider().createAndPublishEndpoint(endpointDescription); System.out.println("Web service published successfully!"); } } Web service published successfully! package com.example; import javax.xml.namespace.QName; import javax.xml.ws.Service; import java.net.URL; public class WebServiceClient { public static void main(String[] args) throws Exception { URL url = new URL("http://localhost:8080/hello?wsdl"); QName qname = new QName("http://example.com/", "HelloWorldService"); Service service = Service.create(url, qname); HelloWorldService hello = service.getPort(HelloWorldService.class); System.out.println(hello.sayHello()); } } Hello, World!


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