0

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 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.