WSDL Tutorials - Herong's Tutorial Examples - v2.22, by Herong Yang
SoapVar Constructor - Creating Encoded Values
This section provides a tutorial example on how to create input parameters with type encoded values. Built-in types are XSD_STRING, XSD_BOOLEAN, XSD_DECIMAL, XSD_DATE, XSD_ANYXML, etc.
In the previous tutorial, I tried to specify input parameter names with the SoapParam constructor. It did not work because my WSDL document has parameter names explicitly defined.
In this tutorial, I want test the SoapVar constructor, which can be used to encode strings into SOAP values:
$value = new SoapVar($string, encoding);
"encoding" should be one of predefined constants like: XSD_STRING, XSD_BOOLEAN, XSD_DECIMAL, XSD_DATETIME, XSD_TIME, XSD_DATE, XSD_ANYURI, XSD_ANYXML, etc.
Here is my testing tutorial program, SoapClient_SoapVar.php:
<?php
# SoapClient_SoapVar.php
# Copyright (c) 2007 HerongYang.com. All Rights Reserved.
#
#- Loading the WSDL document
$server = "https://www.herongyang.com/Service/";
$wsdl = $server . "GetStockPrice_WSDL_11_SOAP_11_RPC.wsdl";
$client = new SoapClient($wsdl,
array('trace' => TRUE));
#- Test 1: Calling with values directly
$result = $client->GetStockPrice('GOOG', 'NASDAQ', '2007-07-07');
print $client->__getLastRequest()."\n";
#- Test 2: Calling with SoapVal objects correct encoding types
$stock = new SoapVar("GOOG", XSD_STRING);
$market = new SoapVar("NASDAQ", XSD_STRING);
$date = new SoapVar("2007-07-07", XSD_DATE);
$result = $client->GetStockPrice($stock, $market, $date);
print $client->__getLastRequest()."\n";
#- Test 3: Calling with SoapVal objects with incorrect encoding types
$stock = new SoapVar("<Stock>GOOG</Stock>", XSD_STRING);
$market = new SoapVar("<Market>NASDAQ</Market>", XSD_ANYXML);
$date = new SoapVar("2007-07-07", XSD_DATETIME);
$result = $client->GetStockPrice($stock, $market, $date);
print $client->__getLastRequest()."\n";
?>
Here is the result of this tutorial program:
<SOAP-ENV:Envelope ...">
<SOAP-ENV:Body>
<SOAP-ENV:GetStockPrice>
<stockPart xsi:type="xsd:string">GOOG</stockPart>
<marketPart xsi:type="xsd:string">NASDAQ</marketPart>
<datePart xsi:type="xsd:date">2007-07-07</datePart>
</SOAP-ENV:GetStockPrice>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
<SOAP-ENV:Envelope ...">
<SOAP-ENV:Body>
<SOAP-ENV:GetStockPrice>
<stockPart xsi:type="xsd:string">GOOG</stockPart>
<marketPart xsi:type="xsd:string">NASDAQ</marketPart>
<datePart xsi:type="xsd:date">2007-07-07</datePart>
</SOAP-ENV:GetStockPrice>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
<SOAP-ENV:Envelope ...">
<SOAP-ENV:Body>
<SOAP-ENV:GetStockPrice>
<stockPart xsi:type="xsd:string"><Stock>GOOG
</Stock></stockPart>
<Market>NASDAQ</Market>
<datePart xsi:type="xsd:dateTime">2007-07-07</datePart>
</SOAP-ENV:GetStockPrice>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
This result is very interesting:
Table of Contents
WSDL 2.0 Document Structure and Syntax
WSDL Version 2.0 Part 2: Adjuncts
WSDL 2.0 Document Examples with SOAP Binding
Using WSDL Document in Java Apache Axis2/Java for WSDL
Apache Woden for WSDL Documents in Java
SoapUI - Web Service Testing Tool
WSDL 1.1 Document Structure and Syntax
WSDL 1.1 Binding Extension for SOAP 1.1
SoapUI as WSDL 1.1 Testing Tool
WSDL 1.1 and SOAP 1.1 Examples - Document and RPC Styles
►PHP SOAP Extension for WSDL 1.1
Testing SOAP Extension with WSDL 1.1
Methods on the SoapClient Class
Calling an RPC Method Based Web Service
encodingStyle="uri" Required for rpc/encoded
SoapParam Constructor - Creating Named Parameters
►SoapVar Constructor - Creating Encoded Values
XSD_ANYXML Encoding - Building SOAP Body Element
Calling an XML Document Based Web Service
Apache Axis2/Java for WSDL 1.1
Using WSDL2Java to Generate Web Service Stub Classes
WSDL 1.1 Binding Extension for SOAP 1.2
WSDL 1.1 and SOAP 1.2 Examples - Document and RPC Styles