【问题标题】:SOAP 1.2 Function ("GetReference") is not a valid method for this serviceSOAP 1.2 函数(“GetReference”)不是此服务的有效方法
【发布时间】:2016-10-29 08:36:30
【问题描述】:

我正在尝试请求服务。

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

【问题讨论】:

    标签: php web-services soap wsdl


    【解决方案1】:

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

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

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

    这告诉您方法GetReference() 采用一个名为$parameters 的参数,该参数必须是GetReference 类型。您可以通过$client-&gt;__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 服务需要身份验证,您必须参考文档以了解其工作原理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-26
      • 2012-01-11
      • 2012-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-03
      • 2017-02-20
      相关资源
      最近更新 更多