duanfazhun0383 2012-03-04 04:53
浏览 206
已采纳

带有命名空间条目数组的PHP SoapHeader

I'm fairly new to PHP's SOAP lib and am having problems creating a valid SoapHeader for the service I'm hitting. Here's the service wsdl:

http://s7sps1api.scene7.com/scene7/webservice/IpsApi-2010-01-31.wsdl

Here's my PHP script:

<?
try {
    $options = array(
        'exceptions'=>true,
        'trace'=>1,
    );

    $ns = 'http://www.scene7.com/IpsApi/xsd';
    $client = new SoapClient('http://s7sps1api.scene7.com/scene7/webservice/IpsApi-2010-01-31.wsdl', $options);
    $auth = (object)array(
        'user'=>'***',
        'password'=>'***'
        );

    $header = new SoapHeader($ns, 'authHeader', $auth, false);
    $client->__setSoapHeaders(array($header));
    $client->getCompanyInfo(array('companyName' => '***'));
    print "<pre>
";
    print "Request :
".htmlspecialchars($client->__getLastRequest()) ."
";
    print "Response:
".htmlspecialchars($client->__getLastResponse())."
";
    print "</pre>";
}
catch(SoapFault $ex)
{
    print "<pre>
";
    print "Request :
".htmlspecialchars($client->__getLastRequest()) ."
";
    print "</pre>";
    var_dump($ex->faultcode, $ex->faultstring, $ex->faultactor, $ex->detail, $ex->_name, $ex->headerfault);
}

?>

When I run it I get the following:

Request :
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.scene7.com/IpsApi/xsd/2010-01-31" xmlns:ns2="http://www.scene7.com/IpsApi/xsd"><SOAP-ENV:Header><ns2:authHeader><user>***</user><password>***</password></ns2:authHeader></SOAP-ENV:Header><SOAP-ENV:Body><ns1:getCompanyInfoParam><ns1:companyName>***</ns1:companyName></ns1:getCompanyInfoParam></SOAP-ENV:Body></SOAP-ENV:Envelope>

string(14) "soapenv:Server" string(11) "ipsApiFault" NULL object(stdClass)#12 (1) { ["ipsApiFault"]=> object(stdClass)#13 (2) { ["code"]=> string(5) "30002" ["reason"]=> string(81) "Missing 'user' element for header '{http://www.scene7.com/IpsApi/xsd}authHeader'." } } NULL NULL

Which is almost where I need it, but the user and password nodes don't have the scene7 namespace like I believe they should.

If I change the auth var to this:

$auth = (object)array(
    'ns2:user' => 'aahardy@adobe.com',
    'ns2:password' => 'lkjasdf1'
    );

it works but it seems hacky that I'm hard-coding ns2. What's the right way to do this?

Thanks!

  • 写回答

1条回答 默认 最新

  • dsvd407787736 2013-01-08 11:17
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 怎么在stm32门禁成品上增加记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 解riccati方程组