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="" xmlns:xsd="" xmlns:soap="">
		<PingHomeImprovementRequest xmlns="http://Reply.LeadMarketPlace.Services.Ping.ServiceContracts/2007/10/ServiceContracts">
		<Category CategoryId="88" Name="Roofing"/>
		<TimeFrame>Timing is Flexible</TimeFrame>
		<BudgetRange>future use</BudgetRange>
		<ProjectStatus>Ready to Hire</ProjectStatus>
		<AdditionalInfo>I have a leaky roof</AdditionalInfo>

I used the following PHP5 code

$client = new SoapClient("", $option);
$client->__soapCall("PingHomeImprovement", array(
                                          '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"?>
          <value>Timing is Flexible</value>
          <value>Requesting a quote</value>
          <value>Ready to Hire</value>
          <value>I have a leaky roof</value>

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


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


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.

$client = new nusoap_client("", 'wsdl');
$err = $client->getError();
if ($err) {
	echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
$params = array('LCPId'=>'999', 
                '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>'; 

POST /pingservice/PingService.asmx HTTP/1.0
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="" xmlns:xsd="" xmlns:xsi="" xmlns:SOAP-ENC="" xmlns:ns2108=""><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