SOAP Binding: Difference between Document and RPC Style Web Services

时间:2023-02-24 17:56:25

SOAP
Binding: Difference between Document and RPC Style Web Services

20FLARES Twitter 1Facebook 9Google+ 8LinkedIn 2Email --Filament.io

A Tutorial on RPC Vs Document Style WSDL SOAP binding with Example

When you create Web Services using SOAP protocol, you follow either Document or RPC SOAP messaging style. In this article, let us discuss about the difference between the Document and RPC style web services. We
use sample example programs which is developed using JAX-WS API from Java.

Basics: Document Style Vs RPC Style

The Document style indicates that the SOAP body contains a XML document which can be validated against pre-defined XML schema document.

RPC indicates that the SOAP message body contains an XML representation of a method call and uses the names of the method and its parameters to generate XML structures that represent a method’s call stack. The document/literal approach is easier because it
simply relies on XML Schema to describe exactly what the SOAP message looks like while transmission.

What is SOAP Encoding and Literal?

SOAP Encoding indicates how a data value should be encoded in an XML format. SOAP Encoding is an extension of the SOAP framework. SOAP encoding offers rules to convert any data value defined in SOAP data model
into XML format.

What is Literal?

In simplest definition, literal it means that the data is serialized according to a schema

Learn by doing: Document Vs RPC Web Services and Artifacts Examples (WSDL,Schema, SEI).

Let us create some sample programs to see the difference between the RPC and Document style web services. In Java using JAX-WS it is very easy to create web services. You can read the below article, if you are
not familiar with JAX-WS.

RPC /LITERAL SOAP Binding Example Web Service

First let us see how the RPC/LITERAL/WRAPPED style web service request and response structure.

The following is a sample Java SEI (Service Endpoint Interface) to create a RPC web service.

/**
 * @author Binu George
 * Globinch.com
 * Visit  http://www.globinch.com. All rights reserved.
 */
package com.my.ws;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.WebParam.Mode;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.ParameterStyle;
import javax.jws.soap.SOAPBinding.Style;
import javax.jws.soap.SOAPBinding.Use;

@WebService(name = "MyJaxWSHello",
		targetNamespace = "http://globinch.com",
		wsdlLocation = "http://globinch.com/ws/MyJaxWS?wsdl")
@SOAPBinding(style=Style.RPC, use=Use.LITERAL, parameterStyle=ParameterStyle.WRAPPED)
public interface MyJaxWSSEI {

	  @WebMethod(operationName="getGreetingRequest")
	  @WebResult(targetNamespace="http://globinch.com/ws/types",
	     name="GreetingResponse")
	  public JXRes getJXWsRes(
	     @WebParam(targetNamespace="http://globinch.com/ws/types",
	               name="name",
	               mode=Mode.IN)
	               String name
	  );

}

The corresponding WSDL and XML schema definition is given below. You can the operation name still appears in the SOAP message. The type encoding info is not present since this is defined as LITERAL.

Schema Defintion

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" targetNamespace="http://globinch.com" xmlns:tns="http://globinch.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="jxRes" type="tns:jxRes"/>
  <xs:complexType name="jxRes">
    <xs:sequence>
      <xs:element name="message" type="xs:string" minOccurs="0"/>
      <xs:element name="name" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

WSDL Document

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.1 in JDK 6. -->
<definitions targetNamespace="http://globinch.com" name="MyJaxWSHelloService" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://globinch.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
  <types>
    <xsd:schema>
      <xsd:import namespace="http://globinch.com" schemaLocation="MyJaxWSHelloService_schema1.xsd"/>
    </xsd:schema>
  </types>
  <message name="getGreetingRequest">
    <part name="name" type="xsd:string"/>
  </message>
  <message name="getGreetingRequestResponse">
    <part name="GreetingResponse" type="tns:jxRes"/>
  </message>
  <portType name="MyJaxWSHello">
    <operation name="getGreetingRequest" parameterOrder="name">
      <input message="tns:getGreetingRequest"/>
      <output message="tns:getGreetingRequestResponse"/>
    </operation>
  </portType>
  <binding name="MyJaxWSSEIPortBinding" type="tns:MyJaxWSHello">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
    <operation name="getGreetingRequest">
      <soap:operation soapAction=""/>
      <input>
        <soap:body use="literal" namespace="http://globinch.com"/>
      </input>
      <output>
        <soap:body use="literal" namespace="http://globinch.com"/>
      </output>
    </operation>
  </binding>
  <service name="MyJaxWSHelloService">
    <port name="MyJaxWSSEIPort" binding="tns:MyJaxWSSEIPortBinding">
      <soap:address location="REPLACE_WITH_ACTUAL_URL"/>
    </port>
  </service>
</definitions>

SOAP Request Message

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:glob="http://globinch.com">
   <soapenv:Header/>
   <soapenv:Body>
      <glob:getGreetingRequest>
         <name>Binu George</name>
      </glob:getGreetingRequest>
   </soapenv:Body>
</soapenv:Envelope>

SOAP Response Message

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:getGreetingRequestResponse xmlns:ns2="http://globinch.com">
         <GreetingResponse>
            <message>Hello</message>
            <name>Binu George</name>
         </GreetingResponse>
      </ns2:getGreetingRequestResponse>
   </S:Body>
</S:Envelope>

From the above you can see that the WSDL is not so complex. It is not very easy to validate the messages since there is no complete schema defined for it. This means the schema alone does not tell you what the
message body Info set contains because some of the soap:body contents comes from WSDL definitions. Because of this , schema describing an RPC/literal message is not sufficient to validate that message.

From the above request and response you can see that the Soap:Body contains one element which has the name of the WSDL operation and the namespace specified on the soap:body element in the WSDL binding. Inside
this element, there’s an element for each part of the message and its name is name of the part. Inside each part element are the contents of that part, as defined by the schema type that the part references in WSDL.

For example see the above response. The

<ns2:getGreetingRequestResponse xmlns:ns2="http://globinch.com">

has the name of the WSDL operation and the namespace specified on the soap:body element in the WSDL binding. Inside this you can see the part element “GreetingResponse” and its content is as per the defined
schema.

Notes on RPC –ENCODED Style and JAX-WS

In JAX-WS RPC/encoded is not supported as a messaging mode. In JAX-WS the “encoded” encoding style isn’t supported and only the “literal” encoding style used.

If you use wsimport/wsgen on wsdl documents/SEI that has use=”encoded” attribute/SOAP binding you may get the following error,

“….. invalid SOAP Binding annotation. Rpc/encoded SOAPBinding is not supported”

Or

“ rpc/encoded wsdls are not supported in JAXWS 2.0.  “

You can use JAX-RPC or Apache Axis V1 , f you want to send SOAP encoded messages or create RPC/encoded style WSDL.

Document/Literal SOAP Binding Web service

Let us now change the style to Document and see the generated schema files and WSDL files. There are two schema files generated and are included in the WSDLfile.

The SEI

/**
 * @author Binu George
 * Globinch.com
 * Visit  http://www.globinch.com. All rights reserved.
 */
package com.my.ws;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.WebParam.Mode;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.ParameterStyle;
import javax.jws.soap.SOAPBinding.Style;
import javax.jws.soap.SOAPBinding.Use;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;

@WebService(name = "MyJaxWSHello",
		targetNamespace = "http://globinch.com",
		wsdlLocation = "http://globinch.com/ws/MyJaxWS?wsdl")
@SOAPBinding(style=Style.DOCUMENT, use=Use.LITERAL, parameterStyle=ParameterStyle.BARE)
public interface MyJaxWSSEI {

	  @WebMethod(operationName="getGreetingRequest")
	  /*@RequestWrapper(targetNamespace="http://globinch.com/ws/types",
	     className="java.lang.String")
	  @ResponseWrapper(targetNamespace="http://globinch.com/ws/types",
	     className="com.my.ws.JXRes")
	  @WebResult(targetNamespace="http://globinch.com/ws/types",
	     name="JXWsRes")*/
	    @WebResult(targetNamespace="http://globinch.com/ws/types",
	     name="GreetingResponse")
	  public JXRes getJXWsRes(
	     @WebParam(targetNamespace="http://globinch.com/ws/types",
	               name="name",
	               mode=Mode.IN)
	               String name
	  );

}

Schema defintion document1

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" targetNamespace="http://globinch.com/ws/types" xmlns:ns1="http://globinch.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:import namespace="http://globinch.com" schemaLocation="MyJaxWSHelloService_schema2.xsd"/>
  <xs:element name="GreetingResponse" nillable="true" type="ns1:jxRes"/>
  <xs:element name="name" nillable="true" type="xs:string"/>
</xs:schema>

Schema defintion document 2

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" targetNamespace="http://globinch.com" xmlns:tns="http://globinch.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="jxRes" type="tns:jxRes"/>
  <xs:complexType name="jxRes">
    <xs:sequence>
      <xs:element name="message" type="xs:string" minOccurs="0"/>
      <xs:element name="name" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

The WSDL Document

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.1 in JDK 6. -->
<definitions targetNamespace="http://globinch.com" name="MyJaxWSHelloService" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://globinch.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
  <types>
    <xsd:schema>
      <xsd:import namespace="http://globinch.com/ws/types" schemaLocation="MyJaxWSHelloService_schema1.xsd"/>
    </xsd:schema>
    <xsd:schema>
      <xsd:import namespace="http://globinch.com" schemaLocation="MyJaxWSHelloService_schema2.xsd"/>
    </xsd:schema>
  </types>
  <message name="getGreetingRequest">
    <part name="name" element="ns1:name" xmlns:ns1="http://globinch.com/ws/types"/>
  </message>
  <message name="getGreetingRequestResponse">
    <part name="GreetingResponse" element="ns2:GreetingResponse" xmlns:ns2="http://globinch.com/ws/types"/>
  </message>
  <portType name="MyJaxWSHello">
    <operation name="getGreetingRequest">
      <input message="tns:getGreetingRequest"/>
      <output message="tns:getGreetingRequestResponse"/>
    </operation>
  </portType>
  <binding name="MyJaxWSSEIPortBinding" type="tns:MyJaxWSHello">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
    <operation name="getGreetingRequest">
      <soap:operation soapAction=""/>
      <input>
        <soap:body use="literal"/>
      </input>
      <output>
        <soap:body use="literal"/>
      </output>
    </operation>
  </binding>
  <service name="MyJaxWSHelloService">
    <port name="MyJaxWSSEIPort" binding="tns:MyJaxWSSEIPortBinding">
      <soap:address location="REPLACE_WITH_ACTUAL_URL"/>
    </port>
  </service>
</definitions>

You can see from the schema and wsdl files that all the elements are defined. The following request and response SOAP messages are following the schema definitions.

Sample SOAP Request

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://globinch.com/ws/types">
   <soapenv:Header/>
   <soapenv:Body>
      <typ:name>Binu George</typ:name>
   </soapenv:Body>
</soapenv:Envelope>

Sample SOAP Response

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns3:GreetingResponse xmlns:ns2="http://globinch.com" xmlns:ns3="http://globinch.com/ws/types">
         <message>Hello</message>
         <name>Binu George</name>
      </ns3:GreetingResponse>
   </S:Body>
</S:Envelope>

In the above SOAP request and response messages, all the elements are defined in the XML schema definition files. But if you use the parameter style as WRAPPED you will see the operation name element in SOAP messages.
Still the definition will be complaint to the XSD. Document style requires extra classes to run the application. You can use “wsgen” to generate all required Java artifacts including mapping classes, wsdl or xsd schema. Read more below

Incoming search terms:

Copied from: http://java.globinch.com/enterprise-java/web-services/soap-binding-document-rpc-style-web-services-difference/

SOAP Binding: Difference between Document and RPC Style Web Services的更多相关文章

  1. Using UTL&lowbar;DBWS to Make a Database 11g Callout to a Document Style Web Service

    In this Document   _afrLoop=100180147230187&id=841183.1&displayIndex=2&_afrWindowMode=0& ...

  2. document&period;all&lpar;&quot&semi;div&rpar;&period;style&period;display &equals; &quot&semi;none&quot&semi;与 等于&quot&semi;&quot&semi;的区别

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. Web Services 中XML、SOAP和WSDL的一些必要知识

    Web Services 是由xml来定义数据格式的,通过SOAP协议在各个系统平台中传输,那么接下来讨论下SOAP和WSDL的各自作用. SOAP和WSDL对Web Service.WCF进行深入了 ...

  4. Web Services之SOAP学习

    Web Services之SOAP [toc] 什么是SOAP SOAP(Simple Object Access Protocol)简单对象访问协议是在分散或分布式的环境中交换信息的简单的协议,是一 ...

  5. Rest风格WEB服务&lpar;Rest Style Web Service&rpar;的真相

    http://blog.csdn.net/jia20003/article/details/8365585 Rest风格WEB服务(Rest Style Web Service)的真相 分类: J2E ...

  6. Using MS Soap toolkit to generate web services &period;md

    Different SOAP encoding styles - RPC, RPC-literal, and document-literal SOAP Remote Procedure Call(R ...

  7. 基于soap 的 python web services 服务开发指南

    文章大纲 序言 相关概念 SOA web services SOAP WSDL UDDI 环境搭建 我们使用 python 3.6 这个较新python 版本 服务端开发 客户端开发 suds-jur ...

  8. 使用LoadRunner对Web Services进行调用--Import Soap

    利用LoadRunner对Web Services进行测试时,通常有三种可供采用的方法: 在LoadRunner的Web Services虚拟用户协议中,[Add Service Call] 在Loa ...

  9. Web Services的相关名词解释:WSDL与SOAP

    在对Web Services进行性能测试时,接触到最多的两个名词就是WSDL和SOAP.利用LoadRunner对Web Services进行调用的时候,也存在两种常用方法,即基于WSDL的[Add ...

随机推荐

  1. python中configparser模块

    python中的configparse模块的使用 主要用来解析一些常用的配置,比如数据配置等. 例如:有一个dbconfig.ini的文件 [section_db1] db = test_db1 ho ...

  2. 调整busybox中syslogd读取内核printk信息长度

    busybox 默认读取内核printk信息长度256, 通过CONFIG_FEATURE_SYSLOGD_READ_BUFFER_SIZE宏可调整, 如下: #cd busybox-1.21.1#m ...

  3. Android Studio MultiDex 分包碰到的坑

    前天准备发包了,测试完毕,打好正式签名包,装到手机上,运行不起来. 网上查了大量资料,都没有解决方案. log显示如下: 04-26 10:07:57.727 1538-1538/? I/MultiD ...

  4. 【BZOJ-1797】Mincut 最小割 最大流 &plus; Tarjan &plus; 缩点

    1797: [Ahoi2009]Mincut 最小割 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1685  Solved: 724[Submit] ...

  5. dotnet il editor 调试 iis 程序

    没有C#源代码,IL级别调试.听说windbg也可以,不过windbg有些难.另外il其实一般写C#程序也不熟,不过我目的只是找出异常点,到客户一般不发pdb文件,出去也是release版本,出异常( ...

  6. 关于JavaScript的模块化

    为什么需要模块化 最近在学习网易微专业的<前端系统架构>课程,里面讲到了关于JavaScript的模块化问题.具体指的是当随着Web系统不断强大起来,需要在客户端进行的操作就多了起来(比如 ...

  7. &lbrack;HNOI 2010&rsqb;Planar

    Description 题库链接 给出 \(T\) 个 \(N\) 个节点 \(M\) 条边的无向图(无重边自环),并给出它们各自的哈密顿回路.分别判断每个图是否是平面图. \(T\leq 100,3 ...

  8. 朱晔和你聊Spring系列S1E2:SpringBoot并不神秘

    朱晔和你聊Spring系列S1E2:SpringBoot并不神秘 [编辑器丢失了所有代码的高亮,建议查看PDF格式文档] 文本我们会一步一步做一个例子来看看SpringBoot的自动配置是如何实现的, ...

  9. 本地存储之sessionStorage

    源码可以到GitHub上下载! sessionStorage: 关闭浏览器再打开将不保存数据   复制标签页会连同sessionStorage数据一同复制 复制链接地址打开网页不会复制seession ...

  10. P3167 &lbrack;CQOI2014&rsqb;通配符匹配

    吐槽 本来是去写AC自动机的,然后发现数据范围每个串100000,有100个串(???),连塞进trie树里都塞不进去,玩个鬼的AC自动机啊,tag不要乱打啊 最后拿字符串hash+爆搜一发搜过去了. ...