Help With SOAP

I’m fairly new to soap but I’m trying to get it working with PHP5. I’ve searched google but have come up with nothing, part of the problem is I’m not even sure what to search for.

Basically we were given the following soap example

<?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="http://schemas.xmlsoap.org/soap/envelope/">
	<soap:Body>
		<PingHomeImprovementRequest xmlns="http://Reply.LeadMarketPlace.Services.Ping.ServiceContracts/2007/10/ServiceContracts">
   <HILead>	  
<LCPId>999</LCPId>
<Zipcode>91786</Zipcode>
<Exclusive>Y</Exclusive>
	<Categories>
		<Category CategoryId="88" Name="Roofing"/>
	</Categories>
<>Y</Exclusive>
	<DefaultProjectInfo>
		<TimeFrame>Timing is Flexible</TimeFrame>
		<BudgetRange>future use</BudgetRange>
		<ProjectStatus>Ready to Hire</ProjectStatus>
		<AdditionalInfo>I have a leaky roof</AdditionalInfo>
	</DefaultProjectInfo>
				     </HomeImprovementLead>
		</PingHomeImprovementRequest>
	</soap:Body>
</soap:Envelope>

I used the following PHP5 code

$option=array('trace'=>1);
$client = new SoapClient("http://services.reply.com/pingservice/PingService.asmx?WSDL", $option);
$client->__soapCall("PingHomeImprovement", array(
                                          'LCPId'=>'999', 
                                          'Zipcode'=>'02889',
                                          'Exclusive'=>'Y',
                                          'Categories'=>array('Category'=>array('CategoryId'=>'88', 'Name'=>'Roofing')),
                                          'DefaultProjectInfo'=>array('TimeFrame'=>'Timing is Flexible', 'BudgetRange'=>'Requesting a quote', 'ProjectStatus'=>'Ready to Hire', 'AdditionalInfo'=>'I have a leaky roof')
                                          )
                                          );

echo 'Request: '.$client->__getLastRequest().''; 

But the __getLastRequest outputs this Soap XML:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope 
        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
        xmlns:ns1="http://Reply.LeadMarketPlace.Services.Ping.ServiceContracts/2007/10/ServiceContracts">
  <SOAP-ENV:Body>
    <ns1:PingHomeImprovementRequest/>
      <param1>02889</param1>
      <param2>Y</param2>
      <param3>
        <item>
          <key>Category</key>
          <value>
            <item>
              <key>CategoryId</key>
              <value>88</value>
            </item>
            <item>
              <key>Name</key>
              <value>Roofing</value>
            </item>
          </value>
        </item>
      </param3>
      <param4>
        <item>
          <key>TimeFrame</key>
          <value>Timing is Flexible</value>
        </item>
        <item>
          <key>BudgetRange</key>
          <value>Requesting a quote</value>
        </item>
        <item>
          <key>ProjectStatus</key>
          <value>Ready to Hire</value>
        </item>
        <item>
          <key>AdditionalInfo</key>
          <value>I have a leaky roof</value>
        </item>
      </param4>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

How do I format the SOAP envelope to match the example provided? Thanks for any help.

Anyone?

Please see nusoap. this helps to deal with soap part in well manner.
You may search google on soap tutorials. You will get more than one.

I found it better to do it with objects as follows:

$params->LCPId = '999';
$params->Zipcode = '02889';
$params->Exclusive = 'Y';
$params->Categories->Category->CategoryId = '88';

... etc

$client->PingHomeImprovement($params);

You’re using WSDLs so it should build it with that. Arrays can be tricky, but not impossible. I recently solved that one in a topic of mine on here.

Dunno if it helps, hope it does

I tried nusoap. But that just returns an empty envelope.

require_once('nusoap/lib/nusoap.php');
$client = new nusoap_client("http://services.reply.com/pingservice/PingService.asmx?WSDL", 'wsdl');
$err = $client->getError();
if ($err) {
	echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$params = array('LCPId'=>'999', 
                'Zipcode'=>'02889',
                'Exclusive'=>'Y',
                'Categories'=>array('Category'=>array('CategoryId'=>'88', 'Name'=>'Roofing')),
                'DefaultProjectInfo'=>array('TimeFrame'=>'Timing is Flexible', 'BudgetRange'=>'Requesting a quote', 'ProjectStatus'=>'Ready to Hire', 'AdditionalInfo'=>'I have a leaky roof')
                ); 
$client->call('PingHomeImprovement', array('Request'=>$params));
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>'; 

Returns:
Request
POST /pingservice/PingService.asmx HTTP/1.0
Host: services.reply.com
User-Agent: NuSOAP/0.7.3 (1.114)
Content-Type: text/xml; charset=ISO-8859-1
SOAPAction: “http://Reply.LeadMarketPlace.Services.Ping.ServiceContracts/2007/11/PingHomeImprovement
Content-Length: 486

<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 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:ns2108="http://tempuri.org"><SOAP-ENV:Body><PingHomeImprovementRequest xmlns="http://Reply.LeadMarketPlace.Services.Ping.ServiceContracts/2007/10/ServiceContracts"/></SOAP-ENV:Body></SOAP-ENV:Envelope>

I also tried making it an object but I kept getting something about it needed to be an array for __soapCall().

Because you’re using __soapCall() and not the method I posted above :lol: Notice my final line of code above where I call the PingHomeImprovement() method directly via the object, and not using __soapCall(). After a load of messing around I found it to be the easiest and most reliable option in PHP 5.2 (what we have available) and should do what you want perfectly