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

标签 php web-services soap wsdl

我正在尝试请求服务。

这是 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/

相关文章:

php - 扩展 Laravel 的抽象 TestCase 类时出错(错误是说我的扩展类必须是抽象的)

PHP函数有点奇怪

php - 在 PHP 中创建一个文件进度条

java - 使用 java 验证 .wsdl 文件的 API

javascript - 对 SOAP 服务的预检选项请求不起作用

php - mysql & php : Getting the latest X posts, 然后下一个 X latest 等等

java - 如何更改 Google 应用引擎上 Web 服务调用的默认超时?

C# SOAP : The specified type was not recognized: name ='arrayList'

java - 在 Java 中使用 SOAP Web 服务(具有安全性)

java - 如何对传出的 SOAP 消息应用 XML 签名