dongwuxie5112 2017-10-17 04:25
浏览 55
已采纳

基于PHP的SOAP头如何生成特定格式?

I wanted to generate the following SOAP header format,

<soapenv:Header>
    <SoapHeaderMsg xmlns="http://xyz.com.au">
        <opt:UserSoapHeader>
            <opt:IdentityName>TEST</opt:IdentityName>
            <opt:AuthenticationToken>jjjkjkjkjkjkj</opt:AuthenticationToken>
        </opt:UserSoapHeader>
    </SoapHeaderMsg>
</soapenv:Header>

So i am using the following php functions to generate this,

$this->__setSoapHeaders(array(
            new SoapHeader('http://xyz.com.au', 'SoapHeaderMsg', array(
                new SoapHeader('http://xyz.com.au', 'IdentityName', 'TEST'),
                new SoapHeader('http://xyz.com.au', 'AuthenticationToken', 'jkjkjkk')
            )),
        ));

Which generates following headers which is completely different to what i wanted above ? how do i generate exact same headers using PHP functions like above ?

<SOAP-ENV:Header>
        <ns1:SoapHeaderMsg>
            <SOAP-ENC:Struct>
                <namespace>http://xyz.com.au</namespace>
                <name>IdentityName</name>
                <data>TEST</data>
                <mustUnderstand>false</mustUnderstand>
            </SOAP-ENC:Struct>
            <SOAP-ENC:Struct>
                <namespace>http://xyz.com.au</namespace>
                <name>AuthenticationToken</name>
                <data>hjhhjjhjhjhj</data>
                <mustUnderstand>false</mustUnderstand>
            </SOAP-ENC:Struct>
        </ns1:SoapHeaderMsg>
    </SOAP-ENV:Header>
  • 写回答

1条回答 默认 最新

  • dongpin6941 2017-10-17 07:23
    关注

    array is mostly used on the PHP side, which gets converted to Struct. Can you please try to use object and see if you have any success with it.

    $this->__setSoapHeaders(array(
            new SoapHeader('http://xyz.com.au', 'SoapHeaderMsg', 
                (object)array( 
                    'opt:UserSoapHeader' => (object)array(
                        'opt:IdentityName' => 'TEST',
                        'opt:AuthenticationToken' => 'jkjkjkk'
                    )
            )),
        ));
    

    The request looks like below:

    <?xml version="1.0" encoding="utf-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
                       xmlns:ns1="http://test.domain.com/"
                       xmlns:ns2="http://xyz.com.au">
          <SOAP-ENV:Header>
            <ns2:SoapHeaderMsg>
                  <opt:UserSoapHeader>
                        <opt:IdentityName>TEST</opt:IdentityName>
                        <opt:AuthenticationToken>jkjkjkk</opt:AuthenticationToken>
                  </opt:UserSoapHeader>
            </ns2:SoapHeaderMsg>
          </SOAP-ENV:Header>
          <SOAP-ENV:Body>
                ......
          </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀