SOAP-ERROR:编码对象没有属性

时间:2015-05-27 08:08:59

标签: php soap

我需要发送这个SOAP请求(从SoapUI NG获取它,它在哪里工作):

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:data="http://example.com/rp/data">
   <soapenv:Header>
      <data:AuthorizationHeader soapenv:mustUnderstand="1">
         <data:login>?</data:login>
         <data:password>?</data:password>
      </data:AuthorizationHeader>
   </soapenv:Header>
   <soapenv:Body>
      <data:OperationHistoryRequest>
         <data:Barcode>?</data:Barcode>
         <data:MessageType>?</data:MessageType>
         <data:Language>?</data:Language>
      </data:OperationHistoryRequest>
   </soapenv:Body>
</soapenv:Envelope>

尝试使用此代码:

<?php
    $rp_soap_endpoint = "http://example.com/OperationHistory?wsdl";

    $client_params = array(
        'soap_version' => SOAP_1_2,
        'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
        'encoding' => 'UTF-8',
        'trace' => 1,
        'exceptions' => true,
        'cache_wsdl' => WSDL_CACHE_NONE,
        'features' => SOAP_SINGLE_ELEMENT_ARRAYS
    );

    $client = new SoapClient($rp_soap_endpoint, $client_params);

    $header = new SoapHeader(
        "http://example.com/rp/data",
        "AuthorizationHeader",
        array(
            new SoapVar($rp_user, XSD_STRING, null, null, "login", "data"),
            new SoapVar($rp_password, XSD_STRING, null, null, "password", "data")
        ),
        true);

    $client->__setSoapHeaders($header);

    $body = '<data:OperationHistoryRequest>
                <data:Barcode>?</data:Barcode>
                <data:MessageType>?</data:MessageType>
                <data:Language>?</data:Language>
             </data:OperationHistoryRequest>';

    $result = $client->GetOperationHistory(new SoapVar($body, XSD_ANYXML));

    echo $result;

但收到错误:

Fatal error: Uncaught SoapFault exception: [Sender] SOAP-ERROR: Encoding: object has no 'login' property

修复此代码需要什么?还有:

  1. 如何在请求标头中添加 xmlns:data (或者不需要)?
  2. 是否可以确定变量 body 更正确(使用SoapVar?)?

1 个答案:

答案 0 :(得分:0)

将版本更改为SOAP_1_1和:

array(
    new SoapVar($rp_user, XSD_STRING, null, null, "login", "data"),
    new SoapVar($rp_password, XSD_STRING, null, null, "password", "data")
)

array(
    'login' => $rp_user,
    'password' => $rp_password
)

现在对我有用。