2010-05-03 4 views
1

J'essaie de faire une demande de savon et avoir des difficultés.SOAP Demande PHP5

Voici mon php:

<?php 
$option=array('trace'=>1); 
$soapClient = new SoapClient('http://www.domain.com/ws/AccountManagement.wsdl', $option); 

$headers = array('LOGIN_ID' => '[email protected]', 'LOGIN_PASSWORD' => 'mypassword'); 

$header = new SoapHeader('https://www.domain.com', 'AuthenticationDTO', $headers, false); 

$soapClient->__setSoapHeaders($header); //or array($header) 

$params = array(
'bureauName' => '', 
'businessInformation' => array('address' => array('city' => 'SomeCity'), array('country' => 'US'), array('state' => 'MN'), array('street' => 'Some Address'), array('zipCode' => '33212')), array('businessName' => 'SomeBusinessName'), 
'entityType' => '', 
'listOfSimilars' => 'true', 
); 


try { 
    $result = $soapClient->__call("matchCompany", $params); 
    print_r($result); 
} catch (SoapFault $fault) { 
    echo $fault->faultcode . "-" . $fault->faultstring; 
    echo "REQUEST:\n" . htmlentities($soapClient->__getLastRequest()) . "\n"; 
} 

>

Il échoue sur soapClient__call $.

getLastRequest() produit ce XML:

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://com.dnbi.eai.service.AccountSEI" xmlns:ns2="http://dto.eai.dnbi.com"> 
    <SOAP-ENV:Header> 
    <ns2:AuthenticationDTO> 
     <ns2:LOGIN_ID>[email protected]</ns2:LOGIN_ID> 
     <ns2:LOGIN_PASSWORD>mypassword</ns2:LOGIN_PASSWORD> 
    </ns2:AuthenticationDTO> 
    </SOAP-ENV:Header> 
    <SOAP-ENV:Body> 
    <ns1:matchCompany/> 
    <param1><item> 
     <key>address</key> 
     <value><item> 
     <key>city</key> 
     <value>SomeCity</value> 
     </item></value> 
     </item><item> 
     <key>0</key> 
     <value><item> 
     <key>country</key> 
     <value>US</value> 
     </item></value> 
     </item><item> 
     <key>1</key> 
     <value><item> 
     <key>state</key> 
     <value>MN</value> 
     </item></value> 
     </item><item> 
     <key>2</key> 
     <value><item> 
     <key>street</key> 
     <value>Some Address</value> 
     </item></value> 
     </item><item> 
     <key>3</key> 
     <value><item> 
     <key>zipCode</key> 
     <value>33212</value> 
     </item></value> 
     </item></param1> 
    <param2><item> 
     <key>businessName</key> 
     <value>SomeBusinessName</value> 
     </item></param2> 
    <param3></param3> 
    <param4>true</param4> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

Ce n'est pas la sortie XML correct. Je dois faire quelque chose de mal. En utilisant soapUI je trouve que c'est le XML correct:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dto="http://dto.eai.dnbi.com" xmlns:com="http://com.dnbi.eai.service.AccountSEI"> 
    <soapenv:Header> 
     <dto:AuthenticationDTO> 
     <dto:LOGIN_ID>[email protected]</dto:LOGIN_ID> 
     <dto:LOGIN_PASSWORD>mypassword</dto:LOGIN_PASSWORD> 
     </dto:AuthenticationDTO> 
    </soapenv:Header> 
    <soapenv:Body> 
     <com:matchCompany> 
     <com:in0> 
      <!--Optional:--> 
      <dto:bureauName></dto:bureauName> 
      <!--Optional:--> 
      <dto:businessInformation> 
       <dto:address> 
     <!--Optional:--> 
        <dto:city>SomeCity</dto:city> 
        <dto:country>US</dto:country> 
        <dto:state>MN</dto:state> 
        <dto:street>Some Address</dto:street> 
        <!--Optional:--> 
        <dto:zipCode></dto:zipCode> 
       </dto:address> 
       <!--Optional:--> 
       <dto:businessName>SomeBusinessName</dto:businessName> 
      </dto:businessInformation> 
      <!--Optional:--> 
      <dto:entityNumber></dto:entityNumber> 
      <!--Optional:--> 
      <dto:entityType></dto:entityType> 
      <!--Optional:--> 
      <dto:listOfSimilars>true</dto:listOfSimilars> 
     </com:in0> 
     </com:matchCompany> 
    </soapenv:Body> 
</soapenv:Envelope> 

Quelqu'un peut-il me aider à produire le même XML qui soapUI produit pour moi, mais en utilisant natif client de savon de PHP5?

Merci

Répondre

4

Essayez plutôt ce code. Notez comment il utilise des objets anonymes pour créer la hiérarchie requise:

$options = array(
    'trace' => 1 
); 

$soapClient = new SoapClient('http://www.domain.com/ws/AccountManagement.wsdl', $option); 

$headers = array(
    'LOGIN_ID' => '[email protected]', 
    'LOGIN_PASSWORD' => 'mypassword' 
); 

$header = new SoapHeader('dto', 'AuthenticationDTO', $headers, false); 

$soapClient->__setSoapHeaders($header); 

$matchCompany->in0->bureauName = ''; 
$matchCompany->in0->businessInformation->address->city = 'SomeCity'; 
$matchCompany->in0->businessInformation->address->country = 'US'; 
$matchCompany->in0->businessInformation->address->state = 'MN'; 
$matchCompany->in0->businessInformation->address->street = 'Some Address'; 
$matchCompany->in0->businessInformation->address->zipCode = '33212'; 
$matchCompany->in0->businessInformation->businessName = 'SomeBusinessName'; 
$matchCompany->in0->entityType = ''; 
$matchCompany->in0->listOfSimilars = true; 

try 
{ 
    $result = $soapClient->matchCompany($matchCompany);  
    print_r($result); 
} 
catch(SoapFault $fault) 
{ 
    echo $fault->faultcode . "-" . $fault->faultstring; 
    echo "REQUEST:\n" . htmlentities($soapClient->__getLastRequest()) . "\n"; 
} 
+0

Jon, je vous remercie d'avoir pris le temps de m'aider. Votre semble fonctionner mieux, mais j'ai encore quelques problèmes de connexion. "HTTP-Impossible de se connecter à l'hôte". –

+0

Il semble diviser LOGIN_ID et LOGIN_PASSWORD en "item" et "keys". login_id [email protected] login_password pepper01

+0

ok je suis la question login_id et MOT DE PASSE résolu en utilisant des objets pour eux. Mais je reçois toujours l'erreur "Impossible de se connecter à l'hôte". Ce qui est wierd est que je peux copier et coller le XML que j'ai généré dans soapUI et cela produit des résultats. –