Connecting through PHP
This article provides sample PHP code that allows you to connect to the WebServices API (SOAP). The connection is done using a Zend HTTP Client.
Credits
Thanks to eternalcage.eu and Tomáš Friedrich for providing the sample code.
Request Method
This method sends a general request to the SOAP API.
Request
protected function ProcessRequest( $assembly, $soapAction, $function, $xml, $debug = false)
{
// initialize the client for the SOAP call
$client = new Zend_Http_Client($this->_config['host'].$assembly);
$client->setAuth( $this->_config['user'], $this->_config['password']);
$client->setHeaders("SOAPAction", $soapAction.$function);
$client->setRawData($xml, 'text/xml; charset=utf-8');
// send request and receive a response
$response = $client->request("POST");
// ...
}
Sample Request
public function DataService_LoadData0($dataStructureID,$filterID="",$sortSetID="",$defaultSetID="")
{
$xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>".
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:asap=\"http://asapenginewebapi.advantages.cz/\">".
"<soapenv:Body>".
"<asap:LoadData0>".
"<asap:dataStructureId>".$dataStructureID."</asap:dataStructureId>".
"<asap:filterId>".$filterID."</asap:filterId>".
"<asap:sortSetId>".$sortSetID."</asap:sortSetId>".
"<asap:defaultSetId>".$defaultSetID."</asap:defaultSetId>".
"</asap:LoadData0>".
"</soapenv:Body>".
"</soapenv:Envelope>";
$response = $this->ProcessRequest("dataservice.asmx", "http://asapenginewebapi.advantages.cz/", "LoadData0", $xml);
return $response;
}