Service
ImportJavax.jws.WebMethod;ImportJavax.jws.WebParam;ImportJavax.jws.WebResult;ImportJavax.jws.WebService;Importjavax.jws.soap.SOAPBinding;ImportJavax.jws.soap.SOAPBinding.Style; @WebService (targetnamespace= "http://tempuri.org/") @SOAPBinding (style=style.document) Public InterfaceMyService {@WebMethod string Sayhito (string name); @WebResult (Name= "Sayhelloresult") String SayHello (@WebParam (name= "Name") String name); }
Service Impl
ImportJavax.annotation.Resource;ImportJavax.jws.WebService;Importjavax.servlet.http.HttpServletRequest;ImportJavax.xml.ws.WebServiceContext;ImportJavax.xml.ws.handler.MessageContext;ImportJavax.xml.ws.handler.soap.SOAPMessageContext; @WebService (ServiceName= "MyService", targetnamespace = "http://tempuri.org/", Endpointinterface = "Cn.config.MyService") Public classMyserviceimplImplementsMyService {@Override Publicstring Sayhito (string name) {returnname; } @ResourcePrivateWebservicecontext WSC; @Override Publicstring SayHello (string name) {Messagecontext CTX=Wsc.getmessagecontext (); HttpServletRequest Request=(HttpServletRequest) ctx.get (soapmessagecontext.servlet_request); returnRequest.getcontenttype (); }}
JavaBean Configuration
@Configuration Public classWebserviceconfig {@Bean PublicSimplejaxwsserviceexporter Simplejaxwsserviceexporter () {simplejaxwsserviceexporter sjaxWsServiceExporter =NewSimplejaxwsserviceexporter (); Sjaxwsserviceexporter.setbaseaddress ("Http://localhost:8081/services/"); returnSjaxwsserviceexporter; } @Bean PublicMyserviceimpl Myserviceimpl () {return NewMyserviceimpl (); } }
Server: Tomcat port number: 8081
wsdl:http://localhost:8081/services/helloservice?wsdl
Notes and Notes
(1), Access WebService deployment descriptor via HTTP://LOCALHOST:8081/SERVICES/MYSERVICE?WSDL
There are also auto-generated xsd:http://localhost:8081/services/myservice?xsd=1.
(2), @SOAPBinding (parameterstyle=parameterstyle.wrapped)
Must be added, otherwise it will be an error; Also, if the published method has only one parameter, you can use @soapbinding (parameterstyle=parameterstyle.bare).
(3), @WebService (serviceName = "MyService") the service name is consistent with the bean configured by spring.
(4), WebService port settings do not like the server, this is very important or the server application conflicts with the WebService service will produce a HTTP404 error.
Spring releases JAX-ws Service (ii)