Hi,

I am working on a wbsite for a training centre.
I am querying a web service for the list of their courses.
There are three parametres in the query: centre, coursetype and courselocation.
When querying it directly or using SoapUI it can be queried using 1, 2, 3 or none of the parametres (none returns all courses). However, when I query it from within php I can only get a result if I use the first two parametres, but I want to only use the first "centre" so I can get a full list of all the courses for that centre.

This is my php code but instead of returning all courses for selected centre it will only return coursetype 1's for that centre, again, I need ALL courses returned.

<?php

$wsdl = "https://pm_for_link/courseinfo/courseinfo.asmx?WSDL";    
$client = new SoapClient($wsdl);
$centre = 'CO';   
$parameters = array(
    "centre" => $centre,
    "coursetype" => "1",
    "courselocation" => " ",);  
$values = $client->getCourseInfo($parameters);  
$xml = $values->getCourseInfoResult->any;
print_r($xml);
?>

If I omit the coursetype parametre i get this error message:

Fatal error:  Uncaught SoapFault exception: [Client] looks like we got no XML document in /location_of_file/test.php:15
Stack trace:
#0 /home/digi1816/public_html/test.php(15): SoapClient->__call('getCourseInfo', Array)
#1 /home/digi1816/public_html/test.php(15): SoapClient->getCourseInfo(Array)
#2 {main}
  thrown in /location_of_file/test.php on line 15

this is the SOAP Request and Response:

POST /courseinfo/courseinfo.asmx HTTP/1.1
Host: PM For Host Address
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <getCourseInfo xmlns="http://pm_for_address.com/">
      <centre>string</centre>
      <coursetype>string</coursetype>
      <courselocation>string</courselocation>
    </getCourseInfo>
  </soap12:Body>
</soap12:Envelope>



HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <getCourseInfoResponse xmlns="http://pm_for_address.com/">
      <getCourseInfoResult>xml</getCourseInfoResult>
    </getCourseInfoResponse>
  </soap12:Body>
</soap12:Envelope>

I have tried every combination I can think of but the only one that works and gives me any results is the above one with centre and coursetype parametres set.

Because of client confidentiality I can not put the web service link here but can PM it if anyone thinks they can help.

Appreciate any time or assitance offered,

Donna :)

Hi,

I would like to help, if you can, send me the link.

Thanks Cereal, pm just sent :)

Thanks Cereal for helping with this.

The problem was my client was sending back extra charaters which were causing errors. These articles explain it in detail...

qa-byte-order-mark
detecting-utf-bom-byte-order-mark

I was still struggling to get the result I needed but the following solution from Cereal worked perfect, it emulates a Soap client and although it may not be an ideal solution for everyone because it requires more code its works for me!!!

<?php
    $wsdl   = "https://your-WSDL-address.com/courseinfo/courseinfo.asmx";
    $soap   = <<<EOD
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://your-WSDL-address.com/"><SOAP-ENV:Body><ns1:getCourseInfo><ns1:centre>CO</ns1:centre></ns1:getCourseInfo></SOAP-ENV:Body></SOAP-ENV:Envelope>
EOD;
    $length = strlen($soap);
    $header = array(
        "Host: your-WSDL-address.com",
        "Connection: Keep-Alive",
        "User-Agent: PHP-SOAP/5.5.9-1ubuntu4.9",
        "Content-type: text/xml;charset=utf-8",
        "Accept: text/xml",
        "Cache-Control: no-cache",
        "Pragma: no-cache",
        "SOAPAction: \"http://your-WSDL-address.com/getCourseInfo\"",
        "Content-Length: ".$length,
        );
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL,            $wsdl);
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($curl, CURLOPT_TIMEOUT,        10);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true );
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_POST,           true );
    curl_setopt($curl, CURLOPT_POSTFIELDS,     $soap);
    curl_setopt($curl, CURLOPT_HTTPHEADER,     $header);
    # show request and response headers
    curl_setopt($curl, CURLOPT_VERBOSE,        true);
    $response = curl_exec($curl);
    if($response === false) {
        $err = 'Curl error: ' . curl_error($curl);
        curl_close($curl);
        print PHP_EOL;
        print $err;
        print PHP_EOL;
    } else {
        curl_close($curl);
        print 'Operation completed without any errors';
        print PHP_EOL;
        $load = simplexml_load_string($response);
        # loading the namespace
        $resp = $load->children("http://schemas.xmlsoap.org/soap/envelope/");
        print_r($resp->Body->children());
    }
commented: you're welcome! +13
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.