如何使用 PHP Soap class 客户端创建 SoapCall
How do you make a SoapCall using the PHP Soap class client
我正在尝试使用 PHP Soap 客户端 class 在 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();
}
我还尝试将 "Credentials" 作为数组而不是 class 输入,正如其他一些答案所建议的那样:
$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",
)
);
这是一个非常具体的问题,但我希望这对以后的人有所帮助。
我正在尝试使用 PHP Soap 客户端 class 在 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();
}
我还尝试将 "Credentials" 作为数组而不是 class 输入,正如其他一些答案所建议的那样:
$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",
)
);
这是一个非常具体的问题,但我希望这对以后的人有所帮助。