Web Services - SPLessons

Web Services Document Style Service

Home > Lesson > Chapter 13
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Web Services Document Style Service

Web Services Document Style Service

shape Description

Document style model is that user will have the ability to shape up SOAP body in any way that user need it and the length of the substance of the SOAP message body is any subjective XML occurrence. The Document style is likewise alluded to as Message-Oriented style. The following is the code need to be placed in the code and it will be different to RPC. [java]@SOAPBinding(style = Style.DOCUMENT)[/java]

shape Example

The following are the required files to understand the RPC style and here he user no need to import any jar files why because all the jar will come up with JDK only. HelloWorld.java [java]package com.splessons; import javax.jws.WebMethod; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style; //Service Endpoint Interface @WebService @SOAPBinding(style = Style.DOCUMENT) public interface HelloWorld{ @WebMethod String getHelloWorldAsString(String name); } [/java] The above code is for server application. HelloWorldImpl.java [java]package com.splessons; import javax.jws.WebService; //Service Implementation @WebService(endpointInterface = "com.splessons.HelloWorld") public class HelloWorldImpl implements HelloWorld{ @Override public String getHelloWorldAsString(String name) { return "Hello World JAX-WS " + name; } } [/java] The above code is for server application. Publisher.java [java]package com.splessons; import javax.xml.ws.Endpoint; //Endpoint publisher public class HelloWorldPublisher{ public static void main(String[] args) { Endpoint.publish("http://localhost:7779/ws/hello", new HelloWorldImpl()); } } [/java] The above code is for server application. The following is the link to get the WSDL code. When click on the above link following data will be displayed. [java]<!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --> <!-- Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --> <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://javatpoint.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://javatpoint.com/" name="HelloWorldImplService"> <types/> <message name="getHelloWorldAsString"> <part name="arg0" type="xsd:string"/> </message> <message name="getHelloWorldAsStringResponse"> <part name="return" type="xsd:string"/> </message> <portType name="HelloWorld"> <operation name="getHelloWorldAsString"> <input wsam:Action="http://splessons.com/HelloWorld/getHelloWorldAsStringRequest" message="tns:getHelloWorldAsString"/> <output wsam:Action="http://splessons.com/HelloWorld/getHelloWorldAsStringResponse" message="tns:getHelloWorldAsStringResponse"/> </operation> </portType> <binding name="HelloWorldImplPortBinding" type="tns:HelloWorld"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/> <operation name="getHelloWorldAsString"> <soap:operation soapAction=""/> <input> <soap:body use="literal" namespace="http://splessons.com/"/> </input> <output> <soap:body use="literal" namespace="http://splessons.com/"/> </output> </operation> </binding> <service name="HelloWorldImplService"> <port name="HelloWorldImplPort" binding="tns:HelloWorldImplPortBinding"> <soap:address location="http://localhost:7779/ws/hello"/> </port> </service> </definitions>[/java] HelloWorldClient.java [java]package com.splessons; import java.net.URL; import javax.xml.namespace.QName; import javax.xml.ws.Service; public class HelloWorldClient{ public static void main(String[] args) throws Exception { URL url = new URL("http://localhost:7779/ws/hello?wsdl"); //1st argument service URI, refer to wsdl document above //2nd argument is service name, refer to wsdl document above QName qname = new QName("http://splessons.com/", "HelloWorldImplService"); Service service = Service.create(url, qname); HelloWorld hello = service.getPort(HelloWorld.class); System.out.println(hello.getHelloWorldAsString("SPLESSONS")); } } [/java] The above code is for client application. Output: Now compile the code result is as follows. [java]Hello World JAX-WS SPLESSONS[/java]

Summary

shape Key Poins

  • Thr Style.DOCUMENT line only the difference between RPC and document style.
  • An arguments are sent in XML format.
  • Thr document style is the loosley coupled