SOAP 1.2函数(“GetReference”)不是此服务的有效方法

时间:2016-10-29 08:36:30

标签: 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 ---

1 个答案:

答案 0 :(得分:1)

GetReferenceRq中的WSDL数据类型似乎没有“登录”或“密码”字段。我将告诉你我是如何得出这个结论的,也许它会给别人一些关于如何排除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服务需要身份验证,则必须参考文档以了解其工作原理。