所以我第一次使用 SOAP 并遇到了一些问题。我正在使用 Laminas 肥皂客户端使用 PHP。
我确实发现这篇文章接近我的问题的标记,但也许我不明白解决方案的确切含义。肥皂错误,编码:对象没有“RecordId”属性
所以我有一点 php
<?php
require_once __DIR__ . '/vendor/autoload.php';
class MyResponse {
public $Input;
}
try{
$requestID = GUIDv4();
$appID = 'app-'.$requestID;
$options = array (
'login' => 'username@company',
'password' => 'password',
'encoding' => 'UTF-8',
'classmap' => [
"IRESSSessionStart" => MyResponse::class,
],
);
$sessionStart = array (
'UserName' => 'username',
'CompanyName' => 'company',
'Password' => 'password',
'ApplicationID' => $appID,
'SessionNumberToKick' => -1,
);
$client = new Laminas\Soap\Client('https://webservicestesta.iress.com.au/v4/wsdls.aspx?svc=IRESS&svr=&mf=TimeSeriesGet2', $options);
$result = $client->IRESSSessionStart($sessionStart);
var_dump($result );
}catch(Exception $e){
var_dump(libxml_get_last_error());
echo "<br><br><br>";
echo $e->getMessage();
}
function GUIDv4 ($trim = true){
if (function_exists('openssl_random_pseudo_bytes') === true) {
$data = openssl_random_pseudo_bytes(16);
$data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100
$data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}
return $guidv4;
}
?>
这是我尝试与之交互的 WSDL 的一部分,因为我需要来自 IRESSSessionStart 的响应来发出进一步的请求。
<xsd:element name="IRESSSessionStart">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Input" type="tns:IRESSSessionStartInput" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
这是调用 IRESSSessionStart 的示例响应
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<IRESSSessionStartResponse xmlns="http://webservices.iress.com.au/v4/">
<Output>
<Input>
<Header>
<SessionKey/>
<RequestID>fb417c8d-317f-40fa-98b7-d2c5e00281b8</RequestID>
<Updates>false</Updates>
<Timeout>25</Timeout>
<PageSize>0</PageSize>
<WaitForResponse>true</WaitForResponse>
<PagingBookmark xsi:nil="true"/>
<PagingDirection>0</PagingDirection>
</Header>
<Parameters>
<UserName>username</UserName>
<CompanyName>company</CompanyName>
<Password>******</Password>
<ApplicationID>9dbe8889-2c11-47a1-b182-cde7838a2265</ApplicationID>
<ApplicationLabel>WebServicesTester</ApplicationLabel>
<PreviousSessionKey xsi:nil="true"/>
<SessionTimeout xsi:nil="true"/>
<AuthenticationType xsi:nil="true"/>
<SessionNumberToKick xsi:nil="true"/>
<KickLikeSessions xsi:nil="true"/>
<Locale/>
<LocalePrivateUseSubtags/>
</Parameters>
</Input>
<Result>
<Header>
<RequestID>fb417c8d-317f-40fa-98b7-d2c5e00281b8</RequestID>
<StatusCode>2</StatusCode>
<WebServiceTimeStamp>2021-02-04T10:22:54</WebServiceTimeStamp>
<PagingBookmark></PagingBookmark>
</Header>
<HeaderRow></HeaderRow>
<DataRows xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<DataRow>
<IRESSSessionKey>0F4D5AFF-4140-4B39-B178-B0BB9DA40376-09BEF5B9-00C8-000A-0001-0089@IDS-TEST</IRESSSessionKey>
<UserToken>060FBA0B6824458C162B300EFCC3CFB7AC570000B1EFD82C0F99E540B1C60500453D0000</UserToken>
<LastLoggedInDateTime>2021-02-03T23:22:49.163</LastLoggedInDateTime>
<PasswordExpiryDays xsi:nil="true" />
</DataRow>
</DataRows>
<ErrorRows></ErrorRows>
</Result>
</Output>
</IRESSSessionStartResponse>
</soap:Body>
</soap:Envelope>
因此,当我尝试解决此错误时,我刚刚添加到 laminas 客户端的类映射中的 MyResponse 类的位:
SOAP-ERROR: Encoding: object has no 'Input' property
但是,由于我将 MyResponse 类添加到类映射中,现在我收到了一个额外的:
bool(false)
SOAP-ERROR: Encoding: object has no 'Input' property
所以我需要解决这个编码对象问题,我认为这是因为我没有正确处理响应。