Skip to content

Instantly share code, notes, and snippets.

@johnkary
Created December 4, 2013 03:59
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save johnkary/7782110 to your computer and use it in GitHub Desktop.
Save johnkary/7782110 to your computer and use it in GitHub Desktop.
Example of how to request raw XML via a SoapClient
<?php
use Psr\Log\LoggerInterface;
/**
* Assembles and dispatches the SOAP request body XML and returns the
* Response body XML from the vendor API.
*/
class Request
{
/**
* @var \SoapClient
*/
protected $client;
/**
* @var LoggerInterface
*/
protected $logger;
public function __construct(\SoapClient $client, LoggerInterface $logger)
{
$this->client = $client;
$this->logger = $logger;
}
public function call()
{
if (function_exists('xdebug_disable')) {
xdebug_disable();
}
$xml = '
<some_ns1:List
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:some_ns1="foo:enterprise.some.company.com/some_ns1">
<some_ns1:SomeObject xsi:type="some_ns1:ListRequests">
<objs:ItemId>Value1</objs:ItemId>
<objs:MoreStuff>Value2</objs:MoreStuff>
<objs:AnotherThing>Value3</objs:AnotherThing>
</some_ns1:SomeObject>
</some_ns1:List>';
$soapBody = new \SoapVar($xml, \XSD_ANYXML);
$return = $this->client->__SoapCall('Create', array($soapBody));
$this->logger->debug('Sent SOAP Request XML: ' . $this->getLastRequestXml());
return $return;
}
public function getSoapClient()
{
return $this->client;
}
/**
* Get most recent XML Request sent to SOAP server
*
* @return string
*/
public function getLastRequestXml()
{
return $this->client->__getLastRequest();
}
/**
* Get most recent XML Response returned from SOAP server
*
* @return string
*/
public function getLastResponseXml()
{
return $this->client->__getLastResponse();
}
}
@klesun
Copy link

klesun commented Jul 12, 2016

Thank you a lot

@anantksingh
Copy link

Hi how to use $output_headers in __soapCall

@AlexanderFonsecaDev
Copy link

thank

@JuanBW
Copy link

JuanBW commented Mar 4, 2021

u are the best!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment