标签:
package com.h3c.itac.webservice; import javax.jws.WebService; @WebService public interface IServer { public String sayHello(String name); }
package com.h3c.itac.webservice; import javax.jws.WebService; @WebService(endpointInterface="com.h3c.itac.webservice.IServer") public class Server implements IServer { public String sayHello(String name){ System.out.println("hello "+name); return name; } }
package com.h3c.itac.webservice; import javax.xml.ws.Endpoint; public class PublishServer { public static void main(String[] args){ System.out.println("启动webservice服务!"); Server server=new Server(); Endpoint.publish("http://localhost:9090/web/myWebService", server); System.out.println("server 启动成功!"); } }
This XML file does not appear to have any style information associated with it. The document tree is shown below. <!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI‘s version is JAX-WS RI 2.2.4-b01. --> <!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI‘s version is JAX-WS RI 2.2.4-b01. --> <definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://webservice.itac.h3c.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://webservice.itac.h3c.com/" name="ServerService"> <types> <xsd:schema> <xsd:import namespace="http://webservice.itac.h3c.com/" schemaLocation="http://localhost:9090/web/myWebService?xsd=1"/> </xsd:schema> </types> <message name="sayHello"> <part name="parameters" element="tns:sayHello"/> </message> <message name="sayHelloResponse"> <part name="parameters" element="tns:sayHelloResponse"/> </message> <portType name="Server"> <operation name="sayHello"> <input wsam:Action="http://webservice.itac.h3c.com/Server/sayHelloRequest" message="tns:sayHello"/> <output wsam:Action="http://webservice.itac.h3c.com/Server/sayHelloResponse" message="tns:sayHelloResponse"/> </operation> </portType> <binding name="ServerPortBinding" type="tns:Server"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> <operation name="sayHello"> <soap:operation soapAction=""/> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> </binding> <service name="ServerService"> <port name="ServerPort" binding="tns:ServerPortBinding"> <soap:address location="http://localhost:9090/web/myWebService"/> </port> </service> </definitions>
package com.h3c.itac.webservice; import java.net.MalformedURLException; import java.net.URL; import javax.xml.namespace.QName; import javax.xml.ws.Service; import org.junit.Test; public class TestClient { @Test public void testClient() throws MalformedURLException{ QName qname=new QName("http://webservice.itac.h3c.com/","ServerService"); URL url = new URL("http://localhost:9090/web/myWebService?wsdl"); Service service = Service.create(url, qname); IServer server = service.getPort(IServer.class); String sayHello = server.sayHello("zhangsan"); System.out.println("aaa "+sayHello); } }
1).服务端:
2).客户端:
标签:
原文地址:http://www.cnblogs.com/wlf-919874006/p/4829043.html