【发布时间】:2025-12-10 06:50:01
【问题描述】:
我正在使用 SoapClient 连接到第 3 方服务。大多数时候它工作正常,但每隔一段时间,也许每 100-150 次调用中就会出现一次错误
Soap 失败:SOAP-ERROR:解析架构:complexType 中出现意外
我的代码在重试的 try/catch 中,它将在下一轮运行。但我想检查 WSDL 以找出失败的原因,部分原因是出于我自己的好奇心,以防我需要将其传递给我正在连接的公司。我可以从 SoapFault 获得这些信息吗?还是我必须调用 URL 来获取字符串?恐怕如果我事后得到 WSDL,它可能已经修复了。
$pass = FALSE;
$this->soap = NULL;
$this->session = NULL;
do {
try {
Doc::i("Starting session");
$this->soap = new SoapClient($this->wsdl_url, ['trace' => 1]);
$pass = TRUE;
} catch (\SoapFault $e) {
Doc::e('Soap Failed: ' . $e->getMessage());
if(str_contains($e->getMessage(),'Parsing Schema') && !empty($e->detail)) {
Doc::e($e->detail); // Something new I'm trying to see if it helps
}
} catch (FatalErrorException $e) {
Doc::e("Soap failed really bad: " . $e->getMessage());
} catch (\Exception $e) {
Doc::e("Soap failed bad: " . $e->getMessage());
}
} while (!$pass);
【问题讨论】:
-
__getLastResponse,因为您使用的是trace? -
我找到了
__getLastResponse(),并且也添加了它。我希望下次我收到错误时它可以工作。感谢您的支持! -
祝你好运!这类错误很烦人。我发布了一个官方答案,以防万一最终成功。
标签: php soap-client