您如何使用PHP Soap类客户端进行SoapCall

问题描述 投票:0回答:1

我正在尝试使用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中提供的正文,以获取内容类型为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://resortdata.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本身有关?谢谢你。

php xml web-services soap soap-client
1个回答
0
投票

这里是一些我已成功使用SoapClient的代码。显然,它引用了另一个wsdl,但是您应该能够使用基本结构来满足您的目的。

$soap_options = array('login'=> $soapUser, 'password' => $soapPassword);
$auth_details = base64_encode($soap_user.":".$soapPassword);  
$client = new SoapClient("https://api.url.com/wsadmin/v1/WebService?wsdl", $soap_options);
$header = new SoapHeader("https://api.url.com/wsadmin/v1/WebService/", "authentication", "Basic $auth_details");
$client->__setSoapHeaders($header);

date_default_timezone_set('America/New_York');

$startDate = date('Y-m-d\TH:i:s', strtotime('-14 hours'));
$endDate = date('Y-m-d\TH:i:s', strtotime('-13 hours'));

$runReportParam["criteria"]["time"] = array("start" => $startDate, "end" => $endDate);
$runReportParam["folderName"] = "My Reports";
$runReportParam["reportName"] = "Report 1";

echo date('Y-m-d H:i:s', time());

echo 'Request : <br/><xmp>'; 
print_r($runReportParam);
echo '</xmp>';

try{
    $runReportResult = $client->runReport($runReportParam);


    if(isset($runReportResult->return)){

    }

}catch (Exception $e){
    echo '<br/> Caught exception: ', $e->getMessage(), "/n";

    //<xmp> tag displays xml output in html 
    echo 'Request : <br/><xmp>', 
    $client->__getLastRequest(), 
    '</xmp><br/><br/> Error Message : <br/>', 
    $fault->getMessage();         

}
© www.soinside.com 2019 - 2024. All rights reserved.