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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料