缺少UsernameToken元素

时间:2010-07-19 01:00:14

标签: php soap wsh wso2 usernametoken

我在以下方法中收到请求,但soap消息似乎不包含UsernameToken元素:

$policy = new WSPolicy(
    array(
        'useUsernameToken'=>true
    )
);
$security = new WSSecurityToken(
    array(
        'user'=>$username,
        'passwordType'=>'PlainText',
        'password'=>$password
    )
);
// create client in WSDL mode
$client = new WSClient(
    array (
        'wsdl'=>$service_wsdl,
        'to'=>$service_url,
        'policy'=>$policy,
        'securityToken'=>$security,
        'trace'=>1
    )
);
$proxy = $client->getProxy();
$proxy->Ping();

生成的请求如下所示:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header>
        <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1">
        </wsse:Security>
    </soapenv:Header>
    <soapenv:Body>
        <ns1:Ping xmlns:ns1="http://streamlinedsalestax.org/efile"/>
    </soapenv:Body>
</soapenv:Envelope>

您会注意到UsernameToken元素完全丢失。

1 个答案:

答案 0 :(得分:0)

怎么样......为WSPolicy添加了“安全性”

<?php
$policy = new WSPolicy(
    array('security' => array(
        'useUsernameToken'=>true
    ))
);
$security = new WSSecurityToken(
    array(
        'user'=>$username,
        'passwordType'=>'PlainText',
        'password'=>$password
    )
);
// create client in WSDL mode
$client = new WSClient(
    array (
        'wsdl'=>$service_wsdl,
        'to'=>$service_url,
        'policy'=>$policy,
        'securityToken'=>$security,
        'trace'=>1
    )
);
$proxy = $client->getProxy();
$proxy->Ping();