Hi

I'm trying to send a request to a my webservice using curl

 $content = '<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://www.travelledia.it/XHI" xmlns:ns1="http://localhost/test/soap2/" xmlns:enc="http://www.w3.org/2003/05/soap-encoding">
                   <env:Header/>
                   <env:Body>
                   <ns1:OTA_HotelAvailRQ>
                     <AvailRequestSegments> 
                          <AvailRequestSegment AvailReqType = "Room" ResponseType = "RateInfoDetails"> 
                          <HotelSearchCriteria> 
                          <Criterion> 
                          <HotelRef HotelCode="5095">xxx</HotelRef>
                          </Criterion> 
                          </HotelSearchCriteria> 
                          </AvailRequestSegment> 
                          </AvailRequestSegments> 
                         </ns1:OTA_HotelAvailRQ>
                   </env:Body>
                </env:Envelope>';
// Assign headers
$headers = array("Content-type: text/xml;charset=\"utf-8\"", 
                 "Accept: application/soap+xml, text/*", 
                 "Cache-Control: no-cache", 
                 "Pragma: no-cache", 
                 "Content-length: ".strlen($content),
                ); 
// URL 
$wsdl  = "http://localhost/test/soap2/server/test2.php";
//CURL here
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $wsdl); // pass wsdl url here
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_VERBOSE, '1');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $content); // pass content variable here
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '1');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // pass headers variable here
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '1');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Execute curl here
$resp = curl_exec($ch);
$res = htmlspecialchars($resp, ENT_QUOTES);
$res=str_replace('&gt;&lt;/','&gt; &lt;',$res);
$res=str_replace('&gt;&lt;','&gt;<BR>&lt;',$res);
// print output here
print_r('<pre>');
print_r($res);
print_r('</pre>');
?>

With simple server page I return to the client the response:

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:enc="http://www.w3.org/2003/05/soap-encoding">
<env:Body xmlns:rpc="http://www.w3.org/2003/05/soap-rpc">
<ns1:OTA_HotelAvailRQResponse env:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<rpc:result>return</rpc:result>
<return xsi:type="enc:Struct">
<AvailRequestSegment xsi:type="enc:Struct">
<HotelSearchCriteria xsi:type="enc:Struct">
<Criterion xsi:type="enc:Struct">
<HotelRef xsi:type="xsd:string">xxx</HotelRef> <Criterion> <HotelSearchCriteria> <AvailRequestSegment> <return> <ns1:OTA_HotelAvailRQResponse> <env:Body> <env:Envelope>

So you can see that no attributes is returned and the HotelCode attribute si missing !!!

Why this happens ?
Thanks in advance.
Regards.

Recommended Answers

All 2 Replies

Hi thanks for your reply:

I did some test using SOAPUI with the same request

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://www.travelledia.it/XHI" xmlns:enc="http://www.w3.org/2003/05/soap-encoding">
                   <env:Header></env:Header>
                   <env:Body>
                   <ns1:OTA_HotelAvailRQ>
                     <AvailRequestSegments> 
                          <AvailRequestSegment AvailReqType = "Room" ResponseType = "RateInfoDetails"> 
                          <HotelSearchCriteria> 
                          <Criterion> 
                          <HotelRef HotelCode="5095">xxx</HotelRef>
                          </Criterion> 
                          </HotelSearchCriteria> 
                          </AvailRequestSegment> 
                          </AvailRequestSegments> 
                      </ns1:OTA_HotelAvailRQ>
                   </env:Body>
                </env:Envelope>

And I obtain the same response:

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:enc="http://www.w3.org/2003/05/soap-encoding"><env:Body xmlns:rpc="http://www.w3.org/2003/05/soap-rpc"><ns1:OTA_HotelAvailRQResponse env:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<rpc:result>return</rpc:result>
<return xsi:type="enc:Struct">
<AvailRequestSegment xsi:type="enc:Struct">
<HotelSearchCriteria xsi:type="enc:Struct">
<Criterion xsi:type="enc:Struct">
<HotelRef xsi:type="xsd:string">xxx</HotelRef>
</Criterion>
</HotelSearchCriteria>
</AvailRequestSegment>
</return>
</ns1:OTA_HotelAvailRQResponse>
</env:Body>
</env:Envelope>

So I suppose is not a problem of the request but the response encoding !
This is my server page:

<?php

$server= new SoapServer("test2.wsdl");
$server->setClass("OTA_HotelAvailRQ");
$server->handle();

class OTA_HotelAvailRQ 
{
  function OTA_HotelAvailRQ($xml="error"){


        return $xml;

   }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.