Herong's Tutorial Notes on Web Service and SOAP
Dr. Herong Yang, Version 2.11

SOAP RPC Presentation

Part:   1  2  

(Continued from previous part...)

Using SOAP Messages to Invoke RPC

Invocation of more complicated remote procedures requires SOAP messages. Here is an example.

Example 3 - A user wants to update prices of a list of part numbers in an inventory system with the following RPC:

   updatePrice(List=ArrayOfStructures)

The SOAP message to invoke the above RPC could look like:

<?xml version="1.0"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
 <env:Body 
    env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"
    xmlns:enc="http://www.w3.org/2003/05/soap-encoding">
  <rpc:updatePrice enc:nodeType="struct" xmlns:rpc="http://www.yang.com">
   <rpc:List enc:arraySize="2">
    <rpc:item>
     <rpc:PartNumber>123</rpc:PartNumber>
     <rpc:Price>99.00</rpc:Price>
    </rpc:item>
    <rpc:item>
     <rpc:PartNumber>321</rpc:PartNumber>
     <rpc:Price>199.00</rpc:Price>
    </rpc:item>
   </rpc:List>
  </rpc:updatePrice>
 </env:Body>
</env:Envelope>

RPC Response Messages

Examples of RPC responses:

Example 1 - A user needs to invoke the following RPC on a target system called "inventory":

   getQuantityInStock(PartNumber="123")

This RPC can be invoked as a Web method. The target system will retrieve the current quantity number and send it back in a SOAP RPC response message:

<?xml version="1.0"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
 <env:Body 
    env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"
    xmlns:enc="http://www.w3.org/2003/05/soap-encoding">
  <res:response enc:nodeType="struct" xmlns:res="http://www.yang.com">
   <res:result>208</res:result>
  </res:response>
 </env:Body>
</env:Envelope>

Example 2 - Another user needs to invoke the following RPC on a target system called "inventory":

   updateQuantityInStock(PartNumber="123", NewQuantity="200")

This RPC can be invoked as a Web method. The target system will update the quantity and send a SOAP RPC response message back. The target system may decide to include the updated quantity as the return value, and the previous value as an output parameter:

<?xml version="1.0"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
 <env:Body 
    env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"
    xmlns:enc="http://www.w3.org/2003/05/soap-encoding">
  <res:response enc:nodeType="struct" xmlns:res="http://www.yang.com">
   <res:result>200</res:result>
   <res:previousQuantity>208</res:previousQuantity>
  </res:response>
 </env:Body>
</env:Envelope>

Example 3 - A user wants to update prices of a list of part numbers in an inventory system with the following RPC:

   updatePrice(List=ArrayOfStructures)

This RPC can be invoked with a SOAP RPC invocation message. The target system will update prices based on the list received as an input parameter and send a SOAP RPC response message. The target system may decide to include the number of prices that have been updated as the return value:

<?xml version="1.0"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
 <env:Body 
    env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"
    xmlns:enc="http://www.w3.org/2003/05/soap-encoding">
  <res:response enc:nodeType="struct" xmlns:res="http://www.yang.com">
   <res:result>2</res:result>
  </res:response>
 </env:Body>
</env:Envelope>

Conclusions

SOAP RPC Presentation offers some simple rules that users should follow when generating RPC invocation SOAP messages and RPC response messages.

Question for you, can the source system invoke RPC as a Web method without any SOAP messages, and allow the target system to return SOAP messages?

Part:   1  2  

Dr. Herong Yang, updated in 2006
Herong's Tutorial Notes on Web Service and SOAP - SOAP RPC Presentation