(PHP 5 >= 5.0.1)
SoapClient::__soapCall — Calls a SOAP function
$function_name
, array $arguments
[, array $options
[, mixed $input_headers
[, array &$output_headers
]]] )This is a low level API function that is used to make a SOAP call. Usually, in WSDL mode, SOAP functions can be called as methods of the SoapClient object. This method is useful in non-WSDL mode when soapaction is unknown, uri differs from the default or when sending and/or receiving SOAP Headers.
On error, a call to a SOAP function can cause PHP to throw exceptions or return a SoapFault object if exceptions are disabled. To check if the function call failed to catch the SoapFault exceptions, check the result with is_soap_fault().
function_name
The name of the SOAP function to call.
arguments
An array of the arguments to pass to the function. This can be either an ordered or an associative array. Note that most SOAP servers require parameter names to be provided, in which case this must be an associative array.
options
An associative array of options to pass to the client.
The location option is the URL of the remote Web service.
The uri option is the target namespace of the SOAP service.
The soapaction option is the action to call.
input_headers
An array of headers to be sent along with the SOAP request.
output_headers
If supplied, this array will be filled with the headers from the SOAP response.
SOAP functions may return one, or multiple values. If only one value is returned by the SOAP function, the return value of __soapCall will be a simple value (e.g. an integer, a string, etc). If multiple values are returned, __soapCall will return an associative array of named output parameters.
On error, if the SoapClient object was constructed with the exceptions
option set to FALSE
, a SoapFault object will be returned.
Example #1 SoapClient::__soapCall() example
<?php
$client = new SoapClient("some.wsdl");
$client->SomeFunction($a, $b, $c);
$client->__soapCall("SomeFunction", array($a, $b, $c));
$client->__soapCall("SomeFunction", array($a, $b, $c), NULL,
new SoapHeader(), $output_headers);
$client = new SoapClient(null, array('location' => "http://localhost/soap.php",
'uri' => "http://test-uri/"));
$client->SomeFunction($a, $b, $c);
$client->__soapCall("SomeFunction", array($a, $b, $c));
$client->__soapCall("SomeFunction", array($a, $b, $c),
array('soapaction' => 'some_action',
'uri' => 'some_uri'));
?>
gonchileon at gmail dot com (2013-07-04 14:25:16)
I'm getting "SoapFault exception: [Client] looks like we got no XML document" when my php soap function returns large data.
Like 900 records of mysql database in xml format.
Anyone knows where's the problem?
Thanks!
php at mattjanssen dot com (2012-10-18 15:48:58)
If you're using a custom class object as a parameter (or nested within your parameters), and you store your data in a $_data[] attribute variable, you need to implement the __get($key) method in that custom class, or your data won't translate/convert into the XML.
<?php
class ColorParam {
private $_data = array();
public function __get($key) {
return $this->_data[$key];
}
public function setBackground($data) {
$this->_data['background'] = $data;
}
}
$client = new SoapClient($wsdl);
$colorParam= new ColorParam();
$colorParam->setBackground('blue');
$client->sampleImageCall($colorParam);
?>
vb (2012-10-17 16:23:19)
Note that calling __soapCall and calling the generated method from WSDL requires specifying parameters in two different ways.
For example, if you have a web service with method login that takes username and password, you can call it the following way:
<?php
$params = array('username'=>'name', 'password'=>'secret');
$client->login($params);
?>
If you want to call __soapCall, you must wrap the arguments in another array as follows:
<?php
$client->__soapCall('login', array($params));
?>
SannerCorp (2012-06-29 02:53:40)
if you are getting this:
Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object hasn't 'comHistorico' property in....
make sure you are calling the right object. I wasted hour on this problem and it wasnt my fault, the provider told me to use this object.
ex. I was calling,
<?php
$client = new SoapClient('https://secure.fcontrol.com.br/WSFControl2/WSFControl2.asmx?wsdl', array('trace' => 1));
$res = $client->analisarTransacao2(array('Name'=>'John', 'Surname' => 'Smith'));
print_r($res);
?>
but instead instead of calling analisarTransacao2 I was suppose to call
enfileirarTransacao4.
Than I got the result I wanted,
stdClass Object ( [enfileirarTransacao4Result] => stdClass Object ( [Sucesso] => [Mensagem] => 154|Usu??rio ou senha inv??lido(s). ) )
Chris Gunawardena (2012-05-14 03:35:35)
For all those poor souls getting the "Fatal error: Uncaught SoapFault exception: [soap:Server] Server was unable to process request. ---> Object reference not set to an instance of an object. in xyz.php" using WSDL.
Aparently all sorts of things cause this but for me the fix was to passin all parameters (not only the requied onces). I just passed the rest as empty strings and the problem was solved.
example below
<?php
ini_set('display_errors', true);
ini_set("soap.wsdl_cache_enabled", "0");
error_reporting(E_ALL);
$client = new SoapClient('http://example.com/searchhsd.asmx?WSDL', array( 'trace' => true, 'exceptions' => true,
'connection_timeout'=>9999,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
'soap_version' => SOAP_1_1, 'encoding' => 'ISO-8859-1',
));
//var_dump($client->__getFunctions());
//var_dump($client->__getTypes());
$search_results_xml = $client->HSDSiteSearch ( array( 'startPos' => 1,
'maxResults' => 100,
'resultOrderVal' => 'Site',
'searchSimilarNames' => true,
'name' => '',
'includePracName' => true,
'suburbsAndPostcodes' => 'Melbourne',
'searchSurroundingSuburbs' => true,
'pcpDesc' => '',
'cityOrShireDesc' => '',
'siteGPDivDesc' => '',
'serviceCategoryDesc' => '',
'serviceTypeDesc' => '',
'keywords' => '',
'targetGroup' => '',
'freeServicesOnly' => false,
'afterHoursOnly' => false,
'startTimeDesc' => '',
'endTimeDesc' => '',
'openOnDesc' => '',
'pracFamilyName' => '',
'pracGivenName' => '',
'pracNoAppointmentRequired' => false,
'pracSpecialInterests' => '',
'pracSexDesc' => '',
'pracLanguageSpokenDesc' => '',
'pracSpecialityDesc' => '',
'pracEthnicityDesc' => ''
) );
print_r($search_results_xml);
/*print "Request: \\n".
$client->__getLastRequestHeaders() ."\\n";
print "Request: \\n".
$client->__getLastRequest() ."\\n";
print "Response: \\n".
$client->__getLastResponseHeaders()."\\n";
print "Response: \\n".
$client->__getLastResponse()."\\n"; */
?>
orrd101 at gmail dot com (2012-05-10 00:18:36)
If you need CDATA from the returned value of the SOAP function you have to do something like this...
<?php
$client = SoapClient("some.wsdl", array('trace' => 1));
$client->SomeFunction();
$responseXML = $client->__getLastResponse();
$response = simplexml_load_string($responseXML, 'SimpleXMLElement', LIBXML_NOCDATA);
?>
snuufix+nospam at gmail dot com (2011-02-11 03:23:14)
I am using SOAP call response headers to sign request results.
After alot of hours, I finally got the best way to get SOAP response headers (other than parsing __getLastResponse() witch requires trace option enabled) is using __soapCall() wrapper.
You can extend SoapClient class and wrap some functions to make sure you get the headers.
<?php
class API extends SoapClient
{
// ... Constructor, etc.
// Get SOAP Server response headers
public function __soapCall($function, $arguments, $options = array(), $input_headers = null, &$output_headers = null)
{
parent::__soapCall($function, $arguments, $options, $input_headers, $output_headers);
print_r($output_headers); // Array of response headers
}
// If you are using WSDL you need this, so you still can call functions directly without calling __soapCall manualy
public function __call($func, $args)
{
return $this->__soapCall($func, $args);
}
?>
niko dot hujanen at gmail dot com (2010-11-09 23:06:12)
I was integrating a local warehouse system with a SOAP to our system and noticed some things.
1) Service uses "dot-namespacing" (fe. Item.Price) I classmapped this to Item_Price and used magical __get() and __set() to strip off 'Item.' from variable names. Works like a charm.
Example:
<Item.Price>1.52</Item.Price>
<?php
class Item_Price {
public $price;
public function __get($field) { $field = str_replace('Item.', '', $field); return $this->$field; }
public function __set($field, $value) { $field = str_replace('Item.', '', $field); $this->$field = $value; }
?>
2) I noticed that classmapping a segment with attributes and value is possible. Class uses variables as attributes and $_ is the value.
Example:
<?php
class Foo {
public $item = 'Bar';
public $_ = 'Value here';
}
?>
Turns to <Foo item="Bar">Value here</Foo>
Example of using classes with soapcalls:
<?php
$client = ExtendSoapClient::getInstance();
$foo = new Foo();
$response = $client->sendFoo($foo);
?>
Posted these since I think the documentation is lacking and very obsolete. Hopefully someone's burden eases.
Anonymous (2010-09-29 14:11:35)
For those getting "SOAP-ERROR: Encoding: object hasn't 'newOrderRequest' property" type errors, there is an additional bug that doesn't seem to be documented anywhere.
For 2+ elements, you need a numeric array but the keys *must* start from 0 and *must* be sequential. If not, you will get this validation error. The fix is as simple as sending the array through array_values().
yoyoy at yopmail dot com (2010-09-24 02:44:15)
Please, please please ...
is it possible to find the name of parameters of any function ?
example
$params = array( 'I_DONT_KNOW_THIS_NAME'=>$val_1, 'I_WANT_TO_FIND_THIS_NAME'=>$val_2 );
$client->call('MethodName', array('parameters' => $params));
thanks
james dot ellis at gmail dot com (2010-06-09 19:12:04)
If you are using this method, remember that the array of arguments need to be passed in with the ordering being the same order that the SOAP endpoint expects.
e.g
<?php
//server expects: Foo(string name, int age)
//won't work
$args = array(32, 'john');
$out = $client->__soapCall('Foo', $args);
//will work
$args = array('john', 32);
$out = $client->__soapCall('Foo', $args);
?>
jarrod at squarecrow dot com (2009-12-16 12:59:17)
If you find yourself needing to consume entire datatables from .NET there are two quick ways to do this.
If you are writing the web services yourself there is a very handy trick to return a datatable as a schema-less XML document. Create a new module file in .NET with this code -
Imports System.Xml
Module PHPDatatable
Public Function parse(ByVal dt As DataTable)
Dim xmlstream As New StringBuilder
Dim write As XmlWriter = XmlWriter.Create(xmlstream)
write.WriteProcessingInstruction("xml", "version='1.0' encoding='utf-8'")
dt.WriteXml(write)
Return xmlstream.ToString()
End Function
End Module
To use it (where MyTable is the datatable we are using.......)
return PHPDatatable.parse(MyTable) 'your return type will need to be a STRING.
Back in PHP, after you have made your SOAP call and have the results you can use SimpleXML to parse out the datatable into an array of objects like so (where $soap are my soap results.......)
<?php
$datatable = simplexml_load_string($soap->myfunctionResult);
?>
In the unfortunate situation where you have no choice but to consume a full-blown datatable (ie: you aren't writing the web services yourself) I have a basic SOAP client available on Codeplex that can parse .NET datatables into an array of objects. http://superdotnet.codeplex.com/
Both methods are fairly simply to implement, and should save you the headache of mapping out your datatables to prebaked .NET objects and manually setting each value.
jarrod at squarecrow dot com (2009-08-10 19:37:47)
When dealing with .NET web services, its a good to remember that moving data back and forth between PHP and .NET can be a little cumbersome if you aren't familiar with the object structures of both.
.NET will return everything inside of an object - usually your function name with "Result" tagged onto the end.
Example.
<?php
$client = new soapclient(SOAP_ADDRESS);
$objectresult = $client->GetDataByID(array('PeopleVendorsID'=> 'N21248'));
?>
.... where GetDataByID is my .NET web service function, PeopleVendorsID is name of the parameter I pass it, and "N21248" happens to be the value of the parameter.
.NET was supposed to return an array to $objectresult but instead I found myself with a triple-nested object.
Basically, if you ever find yourself in a situation where you can't seem to access your data, make use of var_dump.
<?php
var_dump($objectresult);
?>
This will print out a very handy array/object structure for you to sift through - invaluable if you're dealing with cryptic results from .NET.
l dot tomov at raz dot bg (2009-08-01 18:47:00)
I was trying to call a .net service and it took me quite some hours to get the exact object structure.
I was getting a "SOAP-ERROR: Encoding: object hasn't 'newOrderRequest' property"
This is how I got it working:
<?php
class NewOrderRequestElement
{
public $merchantID = "1234";
public $terminalID = "001";
}
class NewOrder
{
public $newOrderRequest;
}
$no = new NewOrder;
$no->newOrderRequest = new NewOrderRequestElement;
$response = $client->NewOrder($no);
?>
And in order to get the exact class structure, you need to call
$client->__getTypes();
Hope this helps somebody.
jayrajput at gmail dot com (2009-06-26 09:56:45)
I see notes from lot of users where they wanted to convert the response to an array.
Problem description as told by one of the user:
--------------------------------------------------------
When a SOAP call returns an array [max_elements=">1"] - you may not actually get an array... (this may be a fault in the wsdl, but it's certainly a potential headache).
foreach($result->field as $field) {
doSomethingWith($field);
}
With more than 1 <field>, you'll loop through the <field> tags (as expected)...
However, with exactly 1 <field>, you'll instead loop through the child elements of the first <field> (almost certainly *not* what you wanted to happen)...
Solution:
-----------
Use SoapClient features option:
new SoapClient($wsdl, array("features" => SOAP_SINGLE_ELEMENT_ARRAYS);
and then the PHP takes care of converting result to an array.
I have been bitten by this before and never looked into this option ...duh...duh
lesley at casbah dot com dot au (2009-04-21 18:55:12)
If you are calling a weblogic service with a certificate and you are getting this error on the soap method call statement:
[EJB:010160]Security Violation: User: '<anonymous>' has insufficient permission to access EJB: type=<ejb>, application=app2_0_52_3, module=appsejb.jar, ejb=AppMethod, method=AppMethod, methodInterface=Remote, signature={java.lang.String}.
then check the wsdl in the soap open call - it must be https. Supplied with an http wsdl this took some time to figure out.
<?php
$client = new SoapClient("https://example.com/AppWs/Service?WSDL",
array('trace'=>true,
'exceptions'=>true,
'local_cert' => "/var/www/html/app/newcert.pem",
'passphrase' => "thepassphrase"));
$response = $client->__soapCall("MyMethod", array("param1" => $value1));
?>
Thanks to the authors for their comments on enabling openssl and curl by uncommenting extension=php_opensll.dll and extension=php_curl.dll in php.ini. Also for Olaf's instructions "append the content of the private key file and the certificate file to a single file". I did this using copy command on the DOS prompt:
copy mycert.pem+mykey.pem newcert.pem
Tim Williams (2009-04-08 06:55:56)
One little gotcha when passing the parameters where you need to have attributes and a simpletype value:
To get the xml
<foo bar="moo">cheese</foo>
You'd pass in:
<?php
array("foo" => array("_" => "cheese", "bar"=>"moo"));
?>
See that "_" bit? It really wasn't obvious from the documentation.
deWarlock (2009-04-02 04:10:23)
The most annoying thing is that you'll get no warning trying to pass object not matching wsdl e.g. if server expects smth like $Object->expName->... and you would pass $Object->otherName the client will send empty request without notifying you.
Also pay attention that names are key sensitive.
In my case I spent hours trying to pass $Post->Lead->... object instead of $Post->lead-> ...
Shto (2009-03-03 03:17:19)
One thing to note.
This happened to me and it took a while until I discovered what the problem was.
I was trying to get .NET objects from a provided web service, however it always seemed to return empty objects. It did return the backbone, but nothing within the objects that made up the structure.
Anyhow, it seems that you have to be very precise with the arrays when calling these functions. Par example, do this:
<?php
$obj = $client->__soapCall($SOAPCall, array('parameters'=>$SoapCallParameters));
?>
meaning that you must put an array as the second argument with 'parameters' as the key and the soap call parameters as the value.
Also make sure that the parameter variable, in my case $SoapCallParameters is in the form of what is requested by the webservice.
So, don't just make an array of the form:
<?php
(
[0] => 'Mary',
[1] => 1983
)
?>
but if the webservice requests a 'muid' variable as 'Mary' and a 'birthyear' as 1983, then make your array like this:
<?php
(
[muid] => 'Mary',
[birthyear] => 1983
)
?>
The above arrays refer to the $SoapCallParameters variable.
Hope this helps somebody, not having to spend too much time figuring out the problems.
dennis at born05 dot nl (2009-02-04 09:43:29)
To properly override the __soapCall() method use the following syntax:
<?php
public function __soapCall ($function_name, $arguments, $options = null, $input_headers = null, &$output_headers = null)
{
// your code goes here..
return parent::__soapCall($function_name, $arguments, $options, $input_headers, $output_headers);
}
?>
This had me puzzled for a while..
uwe dot trotzek at gmx dot de (2009-01-06 01:07:37)
Receiving .NET Datatables in PHP:
<?php
public function getDataBySQL($strSQL){
$arrParams = array( 'strSQL' => $strSQL);
try{
$arrOptions = array('location' => WBSRV_URI);
$this->_sclWebService = new SoapClient(WBSRV_WSDL_PATH, $arrOptions);
$dt = $this->_sclWebService
->getTableFromSQL($arrParams)
->getTableFromSQLResult
->any;
$dt = simplexml_load_string($dt)->NewDataSet;
return $dt;
}catch (Exception $e){
echo $e->getMessage();
}
}
?>
The serialized xml String has to be converted first using the function simplexml_load_string.
Now the complete dataset is represented in $dt
stephan (2008-09-18 22:23:44)
When I try to convert result to array I get "Cannot use object of type stdClass as array ..." so I use next:
<?php
function toArray($obj){
$return=array();
if (is_array($obj)) {
$keys=array_keys($obj);
} elseif (is_object($obj)) {
$keys=array_keys(get_object_vars($obj));
} else {return $obj;}
foreach ($keys as $key) {
$value=$obj->$key;
if (is_array($obj)) {
$return[$key]=toArray($obj[$key]);
} else {
$return[$key]=toArray($obj->$key);
}
}
return $return;
}
?>
skunkrecords at gmail . com (2008-08-30 22:09:31)
I spent an entire day trying to figure out why I couldn't interface with a .net server! Read sethm at uoregon dot edu's comment. It will save your life :P
elementation at gmail dot com (2008-07-30 12:15:44)
Just as a note, when working with base64'd content, calling a function which returns a base64'd binary value will automagically base64_decode() the value for you, rendering any data unusable if you base64_decode() again.
dess at dessben dot net (2008-04-30 01:51:13)
I had several problems with the error "Object reference not set to an instance of an object." with .NET Webservices.
This problem also can be a "non-type" problem.
I can resolved this problem, defining previously the type of the soap functions arguments, with settype() function.
<?php
settype($foo, "string");
?>
sethm at uoregon dot edu (2008-03-25 15:05:29)
Trying to connect to a .NET webservice using the PHP SOAP client, we ran into much strangeness.
When using __soapCall do:
$params = array('a'=>$a, 'b'=>$b);
$result = $client->__soapCall('someFunction', array($params));
When using calling the function directly use:
$params = array('a'=>$a, 'b'=>$b);
$result = $client->someFunction($params);
If $params isn't associative, the client doesn't form the call correctly. Calling it other ways lead to having the first parameter dropped or the parameters not being displayed in the request.
Alejandro Cavallo (2008-03-19 07:38:19)
I get the same problem reported above by ryan:
"ryan at grunt dot tv
22-Sep-2005 01:38
If you want to pass an xml document node as a function parameter, your need to create a SoapVar object with a text represention of the xml node and the XSD_ANYXML encoding constant. However, this constant is not exported by the extension and is not documented for some unknown reason."
When defined variable soapVar I assigned the type XSD_STRING rather than as XSD_ANYXML.
And when calls to the function you must pass the soapVar in an associative array.
For example if the function (called myFunc) expect a parameter called xmlInput you should do something like this:
$soapvar = new SoapVar($query, XSD_STRING);
$result = $client->myFunc(array('xmlInput'=>$soapvar));
This XML fragment are wrapped around xmlImput tags.-
stefan at datax dot biz (2007-10-24 07:28:32)
The call to __soapCall returned an object to me either. This is the function which makes my life easier:
function obj2array($obj) {
$out = array();
foreach ($obj as $key => $val) {
switch(true) {
case is_object($val):
$out[$key] = obj2array($val);
break;
case is_array($val):
$out[$key] = obj2array($val);
break;
default:
$out[$key] = $val;
}
}
return $out;
}
Usage:
...
$response = $client ->__soapCall("track", array('parameters' => $request));
$response = obj2array($response);
Hope it helps.
stephen at sekka dot co dot uk (2007-08-01 07:30:09)
If you are trying to use a .NET web service and every call you make returns the following error,
"Server was unable to process request. --> Object reference not set to an instance of an object."
... then you need to pass Objects into the method rather than the standard variables.
To do this, you need to create mini classes that have properties of the variables you are trying to pass, map them to the types of the WSDL, then pass them into the methods.
Here is an example,
<?php
class Test {
public $account;
public $password;
}
$parameters = new Test;
$parameters -> account = $username;
$parameters -> password = $password;
try {
$client = new SoapClient ("https://www.somewebsite.com/Service.asmx?wsdl", array('classmap' => array('CheckUser' => 'Test')));
$client -> CheckUser ($parameters);
echo "Valid Credentials!";
}
catch (Exception $e) {
echo "Error!<br />";
echo $e -> getMessage ();
}
?>
andrewa at bigpond dot net dot au (2007-06-16 04:14:39)
In response to dumbo's comment on the request not always returning an array:
"more than 1 <field>, you'll loop through the <field> tags (as expected)..."
Here's some quick code to get around it:
<?php
function getArrayFromResponse($data)
{
if (sizeof($data) < 2) {
$new = array();
$new[] = $data;
return $new;
}
return $data;
}
?>
Usage:
$result = $soap->__soapCall('DoSomething', array('parameters' => $param))
foreach(getArrayFromResponse($result['ResponseKeyHere']) as $a) {
// $a will always be an object
}
zeta2ste2000 at yahoo dot it (2007-05-11 01:10:45)
When I have to manage a long number in the header,
the __soapCall function returns a float number in exponential format.
The returned value can't be sent to the server because it is different
from the original one ( for the floating point values limited precision ).
Example :
// Server sended value : 339051398236687110
$soapclient->__soapCall('beginSession',$parameters, null, null,$header);
echo $header["sessionID"]; // returns 3.3905139823669E+17 or 339051398236687050 ( converted to sting)
// and that is different from the original 339051398236687110
$strNum = $soapclient->__getLastResponse();
preg_match("([0-9-]{19,20})", $strNum, $args); // Extracts the correct sessionID value as a string
$headers = new SoapHeader( "http://xml.apache.org/axis/session", "sessionID", $args[0]);
$soapclient->__soapCall('nextCall', $parameters, null, $headers);
bliu at computer dot org (2007-04-16 06:17:09)
Using wsdl file automatically generated by the jboss4.2CR1 deployer,
I tried dozens of methods to marshal parameters to a JAXWS endpoint. And the service constantly got null parameters. At last, I found the right way to call is
<?
$params = array('param1'=>"foo", 'param2'=>"bar");
$client->__soapCall('yourMethod', array('parameters' => $params));
?>
By this way, the parameters' names and values are correctly enclosed by the method name, and the service gives expected replies.
dumbo (2007-04-02 06:02:40)
Note that when a SOAP call returns an array [max_elements=">1"] - you may not actually get an array... (this may be a fault in the wsdl, but it's certainly a potential headache).
foreach($result->field as $field) {
doSomethingWith($field);
}
With more than 1 <field>, you'll loop through the <field> tags (as expected)...
However, with exactly 1 <field>, you'll instead loop through the child elements of the first <field> (almost certainly *not* what you wanted to happen)...
GoodHater (2007-03-14 07:20:18)
I would just like to add to OrionI's example that if the result is an array eg int, int, string, string then those values can be retrieved as follows:
<?php
...
$simpleresult = $objectresult->SumResult;
echo $simpleresult->element name;
temp at mailinator dot com (2007-01-30 04:43:12)
The options in the third argument is documented in http://php.net/manual/en/function.soap-soapclient-construct.php
paulsjv at gmail dot com (2006-01-11 07:44:29)
I was working with SOAP for the first time and I had to create a client that sent a date range to a WSDL (Web Services Description Language) to return some information I needed. I didn't know how to pass the params and there really was no documentation about it. The main thing you have to make sure to do is when you pass params to a method that is definied by the WSDL that you are calling is that you use the same param name for the key of the array or the object variable as shown below. Also, if you don't know what the methods/functions that a WSDL has or the params that you need to pass it you can use the __getFunctions() and __getTypes() methods after you declare your new SoapClient.
<?php
// From and to are the two params that the execute function needs
// when called from the WSDL so make you to have them as the
// key to an array like below
$params["From"] = "06/01/2005"; // also can use $params->From = "date";
$params["to"] = "12/31/2005"; // also can use $params->to = "date";
$client = new SoapClient("some.wsdl");
try {
print($client->execute($params));
} catch (SoapFault $exception) {
echo $exception;
}
?>
ryan at grunt dot tv (2005-09-21 21:38:05)
If you want to pass an xml document node as a function parameter, your need to create a SoapVar object with a text represention of the xml node and the XSD_ANYXML encoding constant. However, this constant is not exported by the extension and is not documented for some unknown reason.
Therefore, to get this to work you must either register the XSD_ANYXML #define as a PHP constant, or use the integer value of the constant when creating the SoapVar, which is 147.
$soapvar = new SoapVar($xml_text, 147);
$params = array("ItemXml" => $soapvar, "PropertyView" => "blah");
$result = $this->soapclient->__soapCall("SaveItem", array("parameters"=>$params), null, $this->soapheaders);
However, this still doesnt give the correct result. For some reason, the ItemXml parameter node is not wrapped around the associated xml parameter in the soap request, and the following soap is produced (assumming '<item>blah</item>' is used as the $xml_text):
<SOAP-ENV:Envelope xmlns:SOAP-ENV="..." xmlns:ns1="...">
<SOAP-ENV:Header>...</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:SaveItem>
<item>blah</item>
<ns1:PropertyView>blah</ns1:PropertyView>
</ns1:SaveItem>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
DesmondJ (2005-05-04 15:36:28)
Following OrionI's example:
<?php
$client = new SoapClient("http://server/sumservice.asmx?WSDL");
$params->a = 2;
$params->b = 3;
$objectresult = $client->Sum($params);
$simpleresult = $objectresult->SumResult;
print($simpleresult); //produces "-1"
?>
Please note that the lines:
"$client->Sum($params);"
and
"$simpleresult = $objectresult->SumResult;"
are based off of each other. If your web service function is called "Sum", then add "Result" to the end of it to get the results of the call.
EG:
<?php
$client = new SoapClient("http://server/mathservice.asmx?WSDL");
$params->a = 2;
$params->b = 3;
$objectresult = $client->Minus($params); // note the name of the function is "Minus"
$simpleresult = $objectresult->MinusResult; // note the name of the result is referenced as "MinusResult"
print($simpleresult); //produces "5"
?>
OrionI (2005-04-18 07:27:38)
Correction on the previously submitted code snippet...the incoming parameter for .NET also has to be in object or array form for it to be correctly converted to the XML form that .NET expects (as already mentioned by Llu?s P?mies). The full example (when using WSDL) should be like this:
<?php
$client = new SoapClient("http://server/myservice.asmx?WSDL");
$params->param1 = $value1;
$params->param2 = $value2;
$objectresult = $client->MyMethod($params);
$simpleresult = $objectresult->MyMethodResult;
?>
So if you have a C# function like this:
//sumservice.asmx
...
[WebMethod]
public int Sum(int a, int b)
{
return a + b;
}
...
The PHP client would be this:
<?php
$client = new SoapClient("http://server/sumservice.asmx?WSDL");
$params->a = 2;
$params->b = 3;
$objectresult = $client->Sum($params);
$simpleresult = $objectresult->SumResult;
print($simpleresult); //produces "5"
?>
OrionI (2005-04-15 11:46:39)
When calling over SOAP to a .NET application, you may end up with an object as a result instead of a simple type, even if you're just grabbing a simple type (like a boolean result). Use a property accessor to get the actual result, like this:
<?php
$client = new SoapClient("http://server/myservice.asmx?WSDL");
$objectresult = $client->MyMethod($param1, $param2);
$simpleresult = $objectresult->MyMethodResult;
?>
Note that .NET seems to name the result MethodNameResult for method MethodName.
(2005-02-17 15:19:14)
If your service is a .NET doc/lit, which means the input message has a single part named 'parameters' that is a structure that wraps the parameters. Your call should look like this:
<?php
$params = array('param_name_1'=>$val_1,'param_name_2'=>$val_2);
$client->call('MethodName', array('parameters' => $params));
?>