gpt4 book ai didi

php - SOAP 1.2 函数 ("GetReference") 不是此服务的有效方法

转载 作者:搜寻专家 更新时间:2023-10-31 21:24:02 24 4
gpt4 key购买 nike

我正在尝试请求服务。

这是 wsdl 文件的链接 WSDL

代码如下

$client = new SoapClient("http://zelsoft.ru/intourxml_v2/BookingService.asmx?WSDL", array(
'soap_version'=> SOAP_1_2,
'exceptions' => 1,
));

$xml = <<<XML
<GetReferenceRq>
<Login>Zelsoft</Login>
<Password>zel123</Password>
<Countries>true</Countries>
<Regions>true</Regions>
</GetReferenceRq>
XML;


$struct = new SoapVar($xml,XSD_ANYXML,"GetReferenceRq");

try{
echo "<pre>";
print_r($client->__getFunctions());
print_r($client->GetReference($struct));
echo "</pre>";
} catch(Exception $e){
echo $e->getMessage();
}

但是我得到一个错误

Function ("GetReference") is not a valid method for this service

$client->__getFunctions()

表示该方法存在

感谢解答

更新

我通过将 soap.wsdl_cache_enabled 设置为 0 解决了这个问题,但遇到了另一个问题

我用这样的代码发送请求

$client = new SoapClient("http://zelsoft.ru/intourxml_v2/BookingService.asmx?WSDL", array(
'soap_version'=> SOAP_1_2,
'exceptions' => 1,
));

class GetReferenceRq{
public $Login = 'Zelsoft';
public $Password = 'zel123';
}

try{
echo "<pre>";
print_r($client->GetReference(new GetReferenceRq()));
echo "</pre>";
} catch(Exception $e){
echo $e->getMessage();
}

但得到回应

System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at Zelsoft.InTourXML.BusinessLogic.Base.GetBaseRqParams(SqlConnection cnn, BaseRq rq)
at Zelsoft.InTourXML.BusinessLogic.Base.Connect(BaseRq rq)
at Zelsoft.InTourXML.BusinessLogic.Reference.GetReference(GetReferenceRq rq)
at Zelsoft.InTourXML.BookingService.GetReference(GetReferenceRq rq)
--- End of inner exception stack trace ---

最佳答案

WSDL 中的 GetReferenceRq 数据类型似乎没有登录或密码字段。我将向您展示我是如何得出这个结论的,也许它会给其他人一些关于如何解决 SOAP 问题的线索。

$client->__getFunctions() 输出中,您可以看到 GetReference 的 API 签名:

array(38) {
[0]=>
string(59) "GetReferenceResponse GetReference(GetReference $parameters)"

这告诉您 GetReference() 方法接受一个名为 $parameters 的参数,该参数必须是 GetReference 类型。您可以通过执行 $client->__getTypes() 找出该数据类型的样子:

array(157) {
[0]=>
string(43) "struct GetReference {
GetReferenceRq rq;
}"
[1]=>
string(569) "struct GetReferenceRq {
boolean Countries;
boolean Regions;
boolean Cities;
boolean Districts;
boolean Meals;
boolean Currencies;
boolean HotelServices;
boolean HotelCategories;
boolean Hotels;
boolean Genders;
boolean RoomTypes;
boolean RoomCategories;
boolean AccommodationTypes;
boolean BookingStatuses;
boolean TransferPointTypes;
boolean TransferPoints;
boolean TransferTypes;
boolean Attractions;
boolean Languages;
boolean HotelChains;
boolean Flights;
boolean TourTypes;
boolean TourDirections;
int CountryId;
int CityId;
int TypeId;
}"

因此您需要创建一个包含 GetReferenceRq 的类。您的代码需要如下所示:

$client = new SoapClient("http://zelsoft.ru/intourxml_v2/BookingService.asmx?WSDL", array(
'soap_version'=> SOAP_1_2,
'exceptions' => 1,
));

class GetReference {
public $rq;
}

class GetReferenceRq{
public $Login = 'Zelsoft';
public $Password = 'zel123';
}

$parameters = new GetReference();
$parameters->rq = new GetReferenceRq();

try{
echo "<pre>";
print_r($client->GetReference($parameters));
echo "</pre>";
} catch(Exception $e){
echo $e->getMessage();
}

但是你现在有新的错误:object has no 'Countries' property。实际上,GetReferenceRq 类型中没有登录和密码字段。相反,您必须添加国家、地区等。

如果 Web 服务需要身份验证,您将必须引用文档以了解其工作原理。

关于php - SOAP 1.2 函数 ("GetReference") 不是此服务的有效方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40317401/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com