Reputation: 91
I am attempting to communicate with an API through PEAR SOAP I am able to create a SOAP request with the following code, but it is not complete.
<?php
require_once 'SOAP/Client.php';
$client = new SOAP_Client('https://api.mindbodyonline.com/0_5/SiteService.asmx?
wsdl',true);
$options = array('namespace' => 'http://schemas.xmlsoap.org/soap/envelope/',
'trace' => 1,
'SOAPAction' => 'http://clients.mindbodyonline.com/api/0_5/GetLocations',
'Host'=> 'clients.mindbodyonline.com'
);
$ret = $client->call(
'GetLocations',
array(
'Request'=>array('SourceCredentials' => array('SourceName'=>'*****','Password'=>'*****************','siteIDs'=> array('int'=>'23661'))),'XMLDetail'=>'Full','PageSize'=>'10','CurrentPageIndex'=>'0')
,$options);
echo '<pre>'.htmlspecialchars($client->getLastRequest()).'</pre>';
?>
This results in the following SOAP Request:
POST /0_5/SiteService.asmx HTTP/1.0
User-Agent: PEAR-SOAP @version@-beta
Host: api.mindbodyonline.com
Content-Type: text/xml; charset=UTF-8
Content-Length: 464
SOAPAction: "http://clients.mindbodyonline.com/api/0_5/GetLocations"
Connection: close
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns4="http://clients.mindbodyonline.com/api/0_5">
<SOAP-ENV:Body>
<ns4:GetLocations>
<Request>Array</Request></ns4:GetLocations>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
When it needs to be in this format:
POST http://clients.mindbodyonline.com/api/0_5/SiteService.asmx HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "http://clients.mindbodyonline.com/api/0_5/GetLocations"
Host: clients.mindbodyonline.com
Content-Length: 795
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<GetLocations xmlns="http://clients.mindbodyonline.com/api/0_5">
<Request>
<SourceCredentials>
<SourceName>{SourceName}</SourceName>
<Password>{Password}</Password>
<SiteIDs>
<int>{SiteID}</int>
</SiteIDs>
</SourceCredentials>
<XMLDetail>Bare</XMLDetail>
<PageSize>10</PageSize>
<CurrentPageIndex>0</CurrentPageIndex>
<Fields>
<string>Locations.Name</string>
<string>Locations.City</string>
</Fields>
</Request>
</GetLocations>
</soapenv:Body>
</soapenv:Envelope>
Maybe I need a fresh set of eyes to look at this as I have been toying with it for MANY hours. Any input or suggestions would be appreciated.
WSDL link is: https://api.mindbodyonline.com/0_5/SiteService.asmx?wsdl
UPDATE: By using SOAP_WSDL class rather then SOAP_Client class I was able to get the XML SOAP request slightly closer to that of the requred version.
<?php
$WSDL=new SOAP_WSDL('https://api.mindbodyonline.com/0_5/SiteService.asmx?wsdl',array (trace=>1));
$proxy=$WSDL->getProxy();
$params = array('Request'=>array('SourceCredentials' => array('SourceName'=>'StudioSevaYoga','Password'=>'******','siteIDs'=>array('int'=>'23661')),'XMLDetail'=>'Full','PageSize'=>'10','CurrentPageIndex'=>'0'));
$options=array('soapaction'=> 'http://clients.mindbodyonline.com/api/0_5/GetLocations');
$ret = $proxy->call("GetLocations",$params,$options);
var_dump($ret);
?>
I am then able to pull this XML SOAP ENVELOPE out of the var_dump:
["outgoing_payload"]=>
string(1118) "POST /0_5/SiteService.asmx HTTP/1.0
User-Agent: PEAR-SOAP @version@-beta
Host: api.mindbodyonline.com
Content-Type: text/xml; charset=UTF-8
Content-Length: 862
SOAPAction: "http://clients.mindbodyonline.com/api/0_5/GetLocations"
Connection: close
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<GetLocations>
<Request>
<SourceCredentials>
<SourceName xsi:type="xsd:string">StudioSevaYoga</SourceName>
<Password xsi:type="xsd:string">*****</Password>
<siteIDs>
<int xsi:type="xsd:string">23661</int></siteIDs></SourceCredentials>
<XMLDetail xsi:type="xsd:string">Full</XMLDetail>
<PageSize xsi:type="xsd:string">10</PageSize>
<CurrentPageIndex xsi:type="xsd:string">0</CurrentPageIndex></Request></GetLocations>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I still recieve this error in the var_dump as well: Server was unable to process request. --- Object reference not set to an instance of an object
If anyone has an eye for pulling problems out of the var_dump, it can be found here: Pear Soap Request Page it seems to repeat the same information numerous times. Any guidance or input is appreciated, thank you.
I am using PEAR SOAP 0.9.1 and PHP 5.2
Upvotes: 2
Views: 1235
Reputation: 91
I was able to make this work by using the advice given here:How to generate a PHP soap client code?..... The PEAR SOAP generateProxyCode() method provided all the proper PEAR SOAP calls and arguments to pass the XML SOAP request to the server correctly. I tied the following php code to the generated services code with success.
<?php
require_once 'SOAP/Client.php';
require_once 'wsdl_proxy.php';
$proxyLocations= new WebService_Site_x0020_Service_Site_x0020_ServiceSoap();
$site=array('int'=>23661);
$Request = array('SourceCredentials' => array('SourceName'=>'StudioSevaYoga','Password'=>'*********','SiteIDs'=>$site),'XMLDetail'=>'Full','PageSize'=>10,'CurrentPageIndex'=>0);
$ret=$proxyLocations->GetLocations($Request);
print_r($Request);
var_dump($ret);
?>
Upvotes: 2