我需要发送这个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
我需要什么来修复这段代码?还有:
- 我如何添加xmlns:data在请求的头(或它是不需要的)?
- 是否可以确定变量体更正确(与SoapVar?)?
更改版本为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
)
现在可以了