我在 centos 服务器(PHP 5.2.10、apache/2.2.3)上设置了 wso2 PHP WS 2.1.0 框架,并且原生 PHP SOAP 扩展处于活动状态。示例 WS 客户端工作正常。我的 WS 安装与默认设置的唯一区别是 wsf 文件位于路径结构 /usr/lib64/php/modules/wsf_c/ 而不是 /var/lib/ 中。
我无法使用以下客户端脚本生成完整的 SOAP 请求 -
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$reqPayloadString = <<<XML
<soap:Envelope xmlns:soap=”http://www.w3.org/2003/05/soap-envelope” xmlns:typ=”http://service.dataxmldistribution.argos.cls.fr/types”>
<soap:Header/>
<soap:Body>
<typ:xmlRequest>
<typ:username>user</typ:username>
<typ:password>password</typ:password>
<typ:platformId>'1,2,3,4,5'</typ:platformId>
<typ:nbDaysFromNow>10</typ:nbDaysFromNow>
</typ:xmlRequest>
</soap:Body>
</soap:Envelope>
XML;
$reqMessage = new WSMessage($reqPayloadString);
try {
$client = new WSClient(array(
"wsdl" => "http://ws-argos.cls.fr/argosDws/services/DixService?wsdl",
"to" => "http://ws-argos.cls.fr/argosDws/services/DixService",
"useSOAP" => 1.2,
"action"=>"getXml"
));
$resMessage = $client->request($reqPayloadString);
printf("Response = %s <br/>\n", htmlspecialchars($resMessage->str));
} catch (Exception $e) {
if ($e instanceof WSFault) {
printf("Soap Fault: %s\n", $e->code);
} else {
printf("Message = %s\n",$e->getMessage());
}
}
printf("<br/> Request = %s </br>",
htmlspecialchars($client->getLastRequest()));
printf("<br/> Response = %s </br>",
htmlspecialchars($client->getLastResponse()));
?>
该脚本返回以下内容 -
Message = Invalid Input Message
Request = <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body></soapenv:Body></soapenv:Envelope>
Response = <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xmlns:xml="http://www.w3.org/XML/1998/namespace" xml:lang="en">Fault occurred while processing.</soap:Text></soap:Reason></soap:Fault></soap:Body></soap:Envelope>
客户端日志显示一个错误 - “om_document.c(102) 无法获取根节点”。
我假设在 getLastRequest 的打印输出中的 body 元素中缺少 xml 请求这一事实,我需要以不同的方式格式化有效负载 xml - 可能使用命名空间?
我不确定这应该是什么样子,因此如果这是问题所在,我将非常感谢任何建议。我已经尝试使用和不使用 WSClient 数组中引用的 'wsdl' 的请求,并尝试将有效负载定义为数组而不是 XML 字符串(就像使用本机 SOAP 请求一样)。
谢谢你,威廉