我创建了一个Web服务并使用soapUI来验证它是否正常工作。但是,PHP客户端在尝试访问它时会收到致命错误。
我有一个try / catch设置,以便我可以查看输出SOAP请求并执行var_dump
。当我查看请求和var_dump
时,它会将其显示为全部小写(即使是我手动键入XML的自定义标头)。
我知道XML区分大小写,当我将请求放回soapUI并正确更改案例时,我会从Web服务获得正确的响应。
什么可能导致SOAP请求更改为小写的所有内容?
//The WSDL url
$wsurl = "http://domain:port/mywebservice.wsdl";
//Custom header setup
$ws_username = 'myuser';
$ws_password = 'mypass';
$ws_authheader = '<wsse:Security soap:mustUnderstand="1" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>'.$ws_username.'</wsse:Username>
<wsse:Password>'.$ws_password.'</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>';
//XML SOAP Security variable
$ws_authvars = new SoapVar($ws_authheader,XSD_ANYXML);
//SOAP Security header
$ws_header = new SoapHeader("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","Security",$ws_authvars);
//SOAP client - trace is set to true so faults can be backtraced
$ws_client = new SoapClient($wsurl, array('trace'=>true));
//SOAP client parameters
$params = array('PARAM1'=>'123456',
'PARAM2'=>'ABCDE',
'PARAM3'=>'ABCD');
try {
//SOAP response
$messages = $ws_client->__soapCall('WSMETHOD',array('parameters'=>$params),NULL, $ws_header);
//print_r($messages);
}
catch (SoapFault $fault) {
echo "\n";
print_r($ws_client->__getLastRequest());
echo "\n";
var_dump($ws_client);
}
我的__getLastRequest返回此值(请注意,字段值保持其正常情况):
<!--?xml version="1.0" encoding="UTF-8"?-->
<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="mynamespaceurl" xmlns:ns2="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<soap-env:header>
<wsse:security soap:mustunderstand="1" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:usernametoken>
<wsse:username>myuser</wsse:username>
<wsse:password>mypass</wsse:password>
</wsse:usernametoken>
</wsse:security>
</soap-env:header>
<soap-env:body>
<ns1:wsmethod>
<ns1:param1>123456</ns1:param1>
<ns1:param2>ABCDE</ns1:param2>
<ns1:param3>ABCD</ns1:param3>
</ns1:wsmethod>
</soap-env:body>
</soap-env:envelope>
确切的SoapFault:
SoapFault exception: [SOAP-ENV:Server] null in C:\inetpub\wwwroot\mydirs\mypage.php:458
Stack trace:
#0 C:\inetpub\wwwroot\mydirs\mypage.php(458): SoapClient >__soapCall('wsmeth...', Array, NULL, Object(SoapHeader))
#1 {main}
它指示的行(458)是$ messages = $ ws_client-&gt; __ soapCall