0

I am attempting to make a SOAP call in PHP using the PHP Soap Client class. I managed to connect to the WDSL file however it isn't accepting my parameters. Here are all the necessary information needed for this call. When I enter the following:

    $wsdlUrl = 'https://irm.cooperboating.com/rdpwincentralsvc/irmpublic.asmx?WSDL';
    $client = new SoapClient($wsdlUrl);
    var_dump($client->__getFunctions());
    var_dump($client->__getTypes());

I get:

  // Output from getFunctions()
  [26]=>
  string(83) "GetCourseInformationResponse GetCourseInformation(GetCourseInformation $parameters)"

  // Output from getTypes()
  [117]=>
  string(63) "struct GetCourseInformation {
     GetCourseInformation_irmRQ RQ;
  }"
  [118]=>
  string(152) "struct GetCourseInformation_irmRQ {
     irmWebSvcCredentials Credentials;
     string CourseNumber;
     string CourseID;
     dateTime StartDate;
     dateTime EndDate;
  }"
  [4]=>
  string(104) "struct irmWebSvcCredentials {
     string LogonID;
     string Password;
     string DataPath;
     string DatabaseID;
  }"

After reading the answer from: How to make a PHP SOAP call using the SoapClient class I have attempted the following:


class irmWebSvcCredentials {

    public function __construct() {
        $this->LogonID = "SomeLogin";
        $this->Password = "SomPass";
        $this->DataPath = "SomePath";
        $this->DatabaseID = "SomeId";
    }
}

try {

    $wsdlUrl = 'https://irm.cooperboating.com/rdpwincentralsvc/irmpublic.asmx?WSDL';
    $client = new SoapClient($wsdlUrl);
    $credentials = new irmWebSvcCredentials();
    $params = array(
        "Credentials" => $credentials,
        "CourseNumber" => "",
        "CourseID" => "",
        "StartDate" => "2019-12-05T18:13:00",
        "EndDate" => "2025-12-29T18:13:00",
    );

    $response = $client->GetCourseInformation(array($params));
    var_dump($response);

}
catch(Exception $e) {
    echo $e->getMessage();
}

I've also tried inputting "Credentials" as just an array instead of a class as some other answers have suggested like so:

    $params = array(
        "Credentials" => array(
            "LogonID" => "SomeLogin",
            "Password" => "SomPass",
            "DataPath" => "SomePath",
            "DatabaseID" => "SomeId",
        ),
        "CourseNumber" => "",
        "CourseID" => "",
        "StartDate" => "2019-12-05T18:13:00",
        "EndDate" => "2025-12-29T18:13:00",
    );

It doesn't seem to matter what I input for the parameters when I call $client->GetCourseInformation, as long as I provide a parameter in the structure of an array it always gives me the same output which is:

object(stdClass)#3 (1) {
  ["GetCourseInformationResult"]=>
  object(stdClass)#4 (3) {
    ["Status"]=>
    int(1)
    ["ErrMsg"]=>
    string(47) "GetCourseInformation_irmRQ is not instantiated."
...

Using Postman I've been able to get the expected output so that leads me to believe that I am not providing a certain parameter. Lastly here is the body I provide in Postman to get the expected output with content type being text/xml:

<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>
    <GetCourseInformation xmlns="http://someurl.com/irmpublic">
      <RQ>
        <Credentials>
         <LogonID>SomeLogin</LogonID>
         <Password>SomPass</Password>
         <DataPath>SomePath</DataPath>
         <DatabaseID>SomeId</DatabaseID>
       </Credentials>
        <CourseNumber></CourseNumber>
        <CourseID></CourseID>
        <StartDate>2019-12-20T18:13:00</StartDate>
        <EndDate>2025-12-29T18:13:00</EndDate>
      </RQ>
    </GetCourseInformation>
  </soap:Body>
</soap:Envelope>

Is there something I'm not providing? Or does this problem have something to do with the API itself?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Paul Kim
  • 17
  • 3
  • a `__construct` method doesn't return a response and even if it did your constructor doesn't attempt to return anything so ` $credentials = new irmWebSvcCredentials();` won't do what I think you hope it might – Professor Abronsius Dec 06 '19 at 19:12
  • What does the documentation for this SOAP endpoint say about authentication? – Professor Abronsius Dec 06 '19 at 19:14
  • I tried 2 different methods regarding this. One with the construct as you mentioned, and another just nesting an array as I mentioned on the question. Both returns the same undesired output. – Paul Kim Dec 06 '19 at 19:15
  • and what format should the auth credentials be supplied? – Professor Abronsius Dec 06 '19 at 19:18
  • `GetCourseInformation_irmRQ is not instantiated` is an interesting error message, and seems to be coming from the API, not your code. You may want to contact the developers of thee API. – aynber Dec 06 '19 at 19:19
  • @aynber That's what I was thinking too. This is my first time using SOAP along with PHP so I wasn't fully certain if it was a mistake with my code or from the API. – Paul Kim Dec 06 '19 at 19:21
  • @RamRaider I think this is what you're looking for string(104) "struct irmWebSvcCredentials { string LogonID; string Password; string DataPath; string DatabaseID; }" – Paul Kim Dec 06 '19 at 19:22

1 Answers1

0

This question has been solved. The answer was in the body provided in Postman.

<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>
    <GetCourseInformation xmlns="http://someurl.com/irmpublic">
      <RQ>           <----- Notice the RQ here
        <Credentials>
         <LogonID>SomeLogin</LogonID>
         <Password>SomPass</Password>
         <DataPath>SomePath</DataPath>
         <DatabaseID>SomeId</DatabaseID>
       </Credentials>
        <CourseNumber></CourseNumber>
        <CourseID></CourseID>
        <StartDate>2019-12-20T18:13:00</StartDate>
        <EndDate>2025-12-29T18:13:00</EndDate>
      </RQ>
    </GetCourseInformation>
  </soap:Body>
</soap:Envelope>

The RQ was never provided so it didn't know how to read the provided parameter. To fix this we simply have to change this:

    $params = array(
        "Credentials" => array(
            "LogonID" => "SomeLogin",
            "Password" => "SomPass",
            "DataPath" => "SomePath",
            "DatabaseID" => "SomeId",
        ),
        "CourseNumber" => "",
        "CourseID" => "",
        "StartDate" => "2019-12-05T18:13:00",
        "EndDate" => "2025-12-29T18:13:00",
    );

To this:

    $params = array(
        "RQ" => array(
            "Credentials" => array(
                "LogonID" => "SomeLogin",
                "Password" => "SomPass",
                "DataPath" => "SomePath",
                "DatabaseID" => "SomeId",
            ),
            "CourseNumber" => "",
            "CourseID" => "",
            "StartDate" => "2019-12-05T18:13:00",
            "EndDate" => "2025-12-29T18:13:00",
        )
    );

This was a very specific question but I hope this helps someone in the future.

Paul Kim
  • 17
  • 3
  • The answer was also in the output from `__getTypes()`. You should mark this answer accepted with the checkmark, as well as any other answers that have been provided to you in the past. Having a 0% accept rate does reduce the chances of getting answers to your questions. – miken32 Jan 22 '20 at 22:12