Reputation: 3217
I'm having a hard time understanding how to create a soap request properly, and to receive info back from the server.
Here's a link to the docs for the service that I need to connect to. It shows the soap request and response format.
https://www.team-intro.com/ws/distributorWS.asmx?op=GetReplicatedSite
Looking at their request format, I'm not sure how I'm suppossed to pass this to their server. I've googled around and found several ways to send requests, but I keep getting soap falut errors. Below is my latest attempt.
<?php
//error_reporting(E_ALL);
//soap connect
$client = new SoapClient("http://www.team-intro.com/ws/distributorWS.asmx?WSDL");
$params = new SoapVar("<soap12:Header><AuthHeader Domain='THEDOMAIN' xmlns='http://www.prodogix.com/'><AuthorizationKey>MYAUTHKEY</AuthorizationKey></AuthHeader></soap12:Header><soap12:Body><GetReplicatedSite xmlns='http://www.prodogix.com/'><website>USERNAME</website></GetReplicatedSite></soap12:Body>", XSD_ANYXML);
//$info[
try {
$result = $client->GetReplicatedSite($params);
}
catch (SoapFault $exception) {
echo $exception;
}
print_r($result);
?>
I've stripped out the input values and replaced them with all caps.
I've also seen people building an array to send to the soap server, but I can't seem to figure out how I pass the extra info like the domain and xmlns in the AuthHeader.
Can anyone point me in the right direction.
Upvotes: 0
Views: 358
Reputation: 3217
This tutorial ended up having the function that I needed:
http://www.xillent.com/blog/codesharing/php-soap-call-for-wsdl-envelope-and-payload/
Here's how the code worked in action incase anyone else has issues like mine.
<?php
//error_reporting(E_ALL);
class feedSoap extends SoapClient
{
var $XMLStr = "";
function setXMLStr ($value){$this->XMLStr = $value; }
function getXMLStr(){return $this->XMLStr; }
function __doRequest($request, $location, $action, $version)
{
$request = $this -> XMLStr;
$dom = new DOMDocument('1.0');
try
{
$dom->loadXML($request);
}
catch (DOMException $e)
{
die($e->code);
}
$request = $dom->saveXML();
//doRequest
return parent::__doRequest($request, $location, $action, $version);
}
function SoapClientCall($SOAPXML)
{
return $this -> setXMLStr ($SOAPXML);
}
}
function soapCall($wsdlURL, $callFunction="", $XMLString)
{
$client = new feedSoap($wsdlURL, array('trace' => true));
$reply = $client-> SoapClientCall($XMLString);
$client->__call("$callFunction", array(), array());
return $client -> __getLastResponse();
}
//i just copied the soap request they provided and dropped in my values (removed for stackoverflow
$XMLString= '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthHeader Domain="THEDOMAIN" xmlns="http://www.prodogix.com/">
<AuthorizationKey>MYKEY</AuthorizationKey>
</AuthHeader>
</soap:Header>
<soap:Body>
<GetReplicatedSite xmlns="http://www.prodogix.com/">
<website>USERSNAMEe</website>
</GetReplicatedSite>
</soap:Body>
</soap:Envelope>';
//set up the url to post the soap request to
$wsdlURL = 'https://www.team-intro.com/ws/distributorWS.asmx?WSDL';
//make the call, and set the soap function that I'll be using
$result = soapCall($wsdlURL, $callFunction="GetReplicatedSite", $XMLString);
print_r($result);
?>
Upvotes: 1