簡體   English   中英

如何使用 PHP Soap 類客戶端進行 SoapCall

[英]How do you make a SoapCall using the PHP Soap class client

我正在嘗試使用 PHP Soap Client 類在 PHP 中進行 SOAP 調用。 我設法連接到 WDSL 文件,但它不接受我的參數。 以下是此次通話所需的所有必要信息。 當我輸入以下內容時:

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

我得到:

  // 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;
  }"

在閱讀以下答案后: How to make a PHP SOAP call using the SoapClient class我嘗試了以下操作:


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();
}

我還嘗試將“憑據”作為數組而不是類輸入,因為其他一些答案建議如下:

    $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",
    );

當我調用 $client->GetCourseInformation 時,我為參數輸入什么似乎並不重要,只要我在數組結構中提供一個參數,它總是給我相同的輸出,即:

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

使用 Postman 我已經能夠獲得預期的輸出,這讓我相信我沒有提供某個參數。 最后,這是我在 Postman 中提供的正文,用於獲取內容類型為 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>

有什么我沒有提供的嗎? 還是這個問題與API本身有關?

這個問題已經解決了。 答案就在 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>

從未提供 RQ,因此它不知道如何讀取提供的參數。 為了解決這個問題,我們只需要改變這個:

    $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",
    );

對此:

    $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",
        )
    );

這是一個非常具體的問題,但我希望這對將來的人有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM