Web Services - SPLessons

Web Services RPC Style Service

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

Web Services RPC Style Service

Web Services RPC Style Service

shape Description

RPC is a convention that one program can use to ask for an administration from a program situated in another PC on a system without understanding the system's points of interest. A methodology call is likewise now and then called as a function call. The following is the structure of the XML-RPC. The RPC infers a part of area transparency, specifically that calling strategies is to a great extent the same whether it is nearby or remote, however generally they are not indistinguishable, so neighborhood calls can be recognized from remote calls. Remote calls are generally requests of extent slower and less dependable than nearby calls, so recognizing them is imperative.

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.RPC) 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 RPC style is the tightly coupled.
  • An arguments are sent as discrete values in RPC style.
  • The RPC is nothing but a request and response model.