views:

94

answers:

1

I'm trying to make a soap request and having difficulties.

Here is my 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";
} 

?>

It fails on $soapClient__call.

getLastRequest() produces this 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"&gt;
  <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>

This is not the correct XML output. I must be doing something wrong. Using soapUI I found that this is the correct XML:

<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"&gt;
   <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>

Can anybody help me produce the same XML that soapUI produced for me, but using PHP5's native Soap client?

Thanks

+3  A: 

Try this code instead. Note how it uses anonymous objects to create the required hierarchy:

$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"; 
} 
Jon Benedicto
Jon, I appreciate you taking the time to help me out. Your seems to be working better, but I'm still having some issues connecting. "HTTP-Could not connect to host".
Tegan Snyder
It seems to be splitting LOGIN_ID and LOGIN_PASSWORD into "item" and "keys". <item> <key>LOGIN_ID</key> <value>[email protected]</value> </item> <item> <key>LOGIN_PASSWORD</key> <value>pepper01</value> </item>
Tegan Snyder
ok i got the LOGIN_ID and PASSWORD issue resolved by using objects for them. But I'm still getting the "Could not connect to host" error. What is wierd is that I can copy and paste the XML that I've generated into soapUI and it produces results.
Tegan Snyder
Update:I knew this same code up on a different server and it works. I must have ports blocked to the outside world on the firewall.
Tegan Snyder