I need to handle external SOAP service with WSDL. Example of valid request (simplified) is:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<RunCommand xmlns="https://me.com/MyService">
<request>
<Credentials>
<User>jack</User>
<Password>abc123</Password>
</Credentials>
<Command xsi:type="SomeCommand">
<Foo>bar</Foo>
</Command>
</request>
</RunCommand>
</soap:Body>
</soap:Envelope>
The problem is that according to WSDL, Command
element is of abstract CommandType
type, so I need to specify xsi:type
. I know how to do it with SoapVar
, but it seems like if I use SoapVar
, all WSDL-mode automation is gone.
For simple WSDLs, that would be enough:
$soapClient->RunCommand([
'Request' => [
'Credentials' => [
'user' => 'jack',
'password' => 'abc123',
],
'Command' => [
'Foo' => 'bar'
]
]
]);
But in this case, I'm getting an exception:
The specified type is abstract: name='CommandType'
I know how to make Command
element for SoapClient
, but I'm not sure how to mix it all together. I tried this:
$soapClient->RunCommand([
'Request' => [
'Credentials' => [
'user' => 'jack',
'password' => 'abc123',
],
new SoapVar(
['Foo' => 'bar'],
SOAP_ENC_OBJECT,
'CommandType',
null,
'Command'
)
]
]);
But it doesn't create a request I need. How can I form the request I need with SoapClient to keep as much WSDL goodies as possible?