J'essaie d'envoyer une requête SOAP à un service de newsletter en utilisant this WSDL.PHP SoapClient request
Voici mon PHP:
$client = new SoapClient($wsdl_url, array(
'login' => 'myusername',
'password' => 'mypassword',
'trace' => true
));
$client->AddSubscriber(
new SoapParam('MyFirstName', 'FirstName'),
new SoapParam('MyLastName', 'LastName'),
new SoapParam('[email protected]', 'Email')
);
Je reçois l'exception:
End element 'Body' from namespace 'schemas.xmlsoap.org/soap/envelope/' expected. Found element 'LastName' from namespace ''. Line 2, position 156.
Voici ce que le service attend pour AddSubscriber:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthHeader xmlns="admin.ekeryx.com">
<Username>string</Username>
<Password>string</Password>
<AccountID>string</AccountID>
</AuthHeader>
</soap:Header>
<soap:Body>
<AddSubscriber xmlns="admin.ekeryx.com">
<subscriber>
<ID>string</ID>
<FirstName>string</FirstName>
<LastName>string</LastName>
<Email>string</Email>
</subscriber>
<overwritable>boolean</overwritable>
</AddSubscriber>
</soap:Body>
</soap:Envelope>
Voici ce qui est envoyé:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="tempuri.org/">
<SOAP-ENV:Body>
<ns1:AddSubscriber/>
<LastName>MyLastName</LastName>
<Email>[email protected]</Email>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Je ne suis pas très familier avec SOAP, et j'ai cherché de la documentation partout, mais je n'arrive pas à trouver une très bonne référence pour ce que je fais.
Toute guidance serait grandement appréciée!
Merci. Pourriez-vous me donner un exemple? Je regarde l'exemple sur le site PHP qui montre:
<?php
class SOAPStruct {
function SOAPStruct($s, $i, $f)
{
$this->varString = $s;
$this->varInt = $i;
$this->varFloat = $f;
}
}
$client = new SoapClient(null, array('location' => "http://localhost/soap.php",
'uri' => "http://test-uri/"));
$struct = new SOAPStruct('arg', 34, 325.325);
$soapstruct = new SoapVar($struct, SOAP_ENC_OBJECT, "SOAPStruct", "http://soapinterop.org/xsd");
$client->echoStruct(new SoapParam($soapstruct, "inputStruct"));
?>
Voulez-vous dire que je dois créer une classe PHP d'abonné, attribuer tous les vars $this->FirstName = $first_name
, etc ... et puis le mettre dans un SoapVar avec l'encodage SOAP_ENC_OBJECT
? Comment puis-je mieux représenter la structure de l'abonné?
S'il vous plaît noter , J'ai supprimé le http: // de toutes les URL dans le code afin de respecter le maximum de 1 lien hypertexte par règle de publication. –