2

我创建了一个 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 &gt;__soapCall('wsmeth...', Array, NULL, Object(SoapHeader)) 
#1 {main}

它指示的行 (458) 是 $messages = $ws_client->__soapCall

4

0 回答 0