ich nicht einen Weg, es zu erreichen, fanden Arrays, aber ich konnte es mit Klassen tun. Der Code:
try {
$options = [
'trace'=> 1,
'location' => 'http://localhost/pruebas/soap-server-nowsdl.php',
'uri' => 'http://localhost/pruebas'
];
class PostCodeRequest {
function __construct($pc)
{
$this->Postcode = $pc;
}
}
$client = new SOAPClient(null, $options);
$pc = new PostcodeRequest('SW1A 1AA');
$postCodeRequest = new SoapVar($pc, SOAP_ENC_OBJECT, 'PostCodeRequest', 'http://soapinterop.org/xsd');
$response = $client->hola(new SoapParam($postCodeRequest, 'RequestDetails'));
header('Content-type:text/xml');
echo $client->__getLastRequest();
}
catch (SoapFault $e) {
echo $e;
}
Wird dies als Antrag geben:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/pruebas" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://soapinterop.org/xsd" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:hola>
<RequestDetails xsi:type="ns2:PostCodeRequest">
<Postcode xsi:type="xsd:string">SW1A 1AA</Postcode>
</RequestDetails>
</ns1:hola>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Natürlich wird dies vorausgesetzt, Sie eine "hola" Funktion in Ihrem SOAP-Server. Ersetzen Sie es mit allem, was Sie anrufen. Diese Lösung basiert auf dem Beispiel SoapVar constructor.
Danke @Eduardo Galvin. –
'$ response = $ client-> hola (neues SoapParam ($ postCodeRequest, 'RequestDetails'));' In diesem, ist ''RequestDetails' 'notwendig? Es scheint nicht in der XML verwendet zu werden. –
@JulianJeyarajah ist erforderlich und wird verwendet, um den Knoten zu benennen. Wenn Sie es in, sagen wir, '' rd'' geändert haben, dann wäre der Elementname ' ... '. –