0

I need to set the SOAP header into this format:

<soapenv:Header>
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <wsse:UsernameToken wsu:Id="UsernameToken-45">
            <wsse:Username>XXXXX</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">XXXXXXX</wsse:Password>
            <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">OxWtCYYj1cX7HiZeMEqorw==</wsse:Nonce>
            <wsu:Created>2013-09-18T07:25:50.227Z</wsu:Created>
        </wsse:UsernameToken>
    </wsse:Security>
</soapenv:Header>

I've tried authenticating the webservice using the code below but it didn't work.

$momurl = "https://integrationdev.momentum.co.za/sales/CRMService/CRMLeadService_v1_0/";

$client = new SoapClient(
    "$momurl",
    array(
        'trace' => 1,
        'login' => $username,
        'password' => $password
    )
);

Any help would be appreciated. Thanks in advance.

maikelsabido
  • 1,253
  • 4
  • 18
  • 37

1 Answers1

5

You need to use SoapClient::__setSoapHeader(). Like this:

$security = array(
    'Username'=>'XXXXX',
    'Password'=>'XXXXX',
    'Nonc'=> 'OxWtCYYj1cX7HiZeMEqorw==',
    'Created' => '2013-09-18T07:25:50.227Z',
    'UsernameToken' => NULL
);

$header = new SoapHeader('wsse','Security',$security, false);
$client->__setSoapHeaders($header);
hek2mgl
  • 152,036
  • 28
  • 249
  • 266
  • 1
    Thanks for the response. I'm sorry but I'm not really familiar with SOAP. Hmmm... How should I implement the SoapClient::__setSoapHeader() ? Where should I put this? – maikelsabido Sep 19 '13 at 09:43
  • Put it below the construtor – hek2mgl Sep 19 '13 at 09:44
  • Okay, this is used for sending requests/connecting to a webservice. The webservice endpoint is $momurl and it should pass some data via the $params variable. Do you know how to perform the request? Thanks – maikelsabido Sep 19 '13 at 09:48
  • I already got the question :) put the code that I gave you below the constructor – hek2mgl Sep 19 '13 at 09:50
  • What do you mean by that? I'm sorry I'm kinda lost 'coz I'm new to these things. :) – maikelsabido Sep 19 '13 at 09:55
  • I would suggest that you follow a simple soap tutorial. If you got the basic things then start with this task (its not trivial) – hek2mgl Sep 19 '13 at 10:02