首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >缺少UsernameToken元素

缺少UsernameToken元素
EN

Stack Overflow用户
提问于 2010-07-19 09:00:14
回答 1查看 974关注 0票数 0

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

代码语言:javascript
复制
$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();

生成的请求如下所示:

代码语言:javascript
复制
<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元素完全丢失了。

EN

回答 1

Stack Overflow用户

发布于 2010-07-19 09:23:59

这样如何..。为WSPolicy添加了“安全”功能

代码语言:javascript
复制
<?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();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3277872

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档