We have an WSDL that contains the following and make a call using the standard SOAP Client of PHP:
<element name="doSomething">
<complexType>
<sequence>
<element name="Payload" nillable="true" type="xsd:string"/>
<element name="Username" type="string"/>
<element name="service" type="string"/>
<element name="Password" type="string"/>
</sequence>
</complexType>
</element>
The Payload is essentially XML data, which looks for example like this
<code>1</code>
Now the request of the SOAP client, dumped via echo $client->__getLastRequest();
looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="pa/WebshopService"><SOAP-ENV:Body><ns1:doSomething><ns1:Payload><code>
1
</code>
</ns1:pcRequest><ns1:Username>bar</ns1:Username><ns1:service>bar</ns1:service><ns1:Password>bar</ns1:Password></ns1:doSomething></SOAP-ENV:Body></SOAP-ENV:Envelope>
which, I believe makes sense, as the <
and >
should be encoded.
The counterpart seems to expect something like this:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="pa/WebshopService"><SOAP-ENV:Body><ns1:doSomething><ns1:Payload><code>
1
</code>
</ns1:pcRequest><ns1:Username>bar</ns1:Username><ns1:service>bar</ns1:service><ns1:Password>bar</ns1:Password></ns1:doSomething></SOAP-ENV:Body></SOAP-ENV:Envelope>
Well, the complex type doSomething
says, that the property Payload
is of type string. Consequently the encoded string of the xml content should be right. If the provider side expects the content not encoded, the property Payload
would be another complex type. So in this case the wsdl is not valid, if it 's true, that the provider side really wants an element and not an encoded string.
Anyway, there 's a solution you can handle this with PHP. Just handle Payload
not as a string. Instead make a complex type out of it.
class DoSomething()
{
protected $Payload;
protected $Username;
protected $Service;
protected $Password;
public function getPayload() : ?\SoapVar {
return $this->Payload;
}
public function setPayload(\SoapVar $payload) : DoSomething
{
$this->Payload = $payload;
return $this;
}
...
public function encode() : \SoapVar
{
return new \SoapVar(
$this,
SOAP_ENC_OBJECT,
null,
null,
'doSomething',
'http://www.example.com/namespace'
);
}
}
Above you see the complex type doSomething
as a PHP class. You also see an examplary getter and setter method. The get method returns null or a \SoapVar instance. The setter method takes a \SoapVar instance.
For your purpose you 'll need another PHP class for the Payload
property, which contains the code
property.
class Payload
{
protected $Code;
public function getCode() : ?\SoapVar
{
return $this->Code;
}
public function setCode(\SoapVar $code) : Payload
{
$this->Code = $code;
return $this;
}
public function encode() : \SoapVar
{
return new \SoapVar
{
$this,
SOAP_ENC_OBJECT,
null,
null,
'Payload',
'http://www.example.com/namespace'
}
}
}
Now just put all together ...
$code = new \SoapVar(1, XSD_INT, null, null, 'code');
$payload = (new Payload())
->setCode($code)
->encode();
$doSomething = (new DoSomething())
->setPayload($payload)
->setUsername(...)
->setService(...)
->setPassword(...)
->encode();
$result = $client->doSomething($doSomething);
Now your request should look like ...
<ns1:doSomething>
<ns1:Payload>
<code>1</code>
</ns1:Payload>
<ns1:Username>...</ns1:Username>
<ns1:Service>...</ns1:Service>
<ns1:Password>...</ns1:Password>
</ns1:doSomething>
Hope that helped you.