Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 806
  • Last Modified:

SOAP request with header data

I'm trying to connect to a WCF service from PHP using the SoapClient class. I can successfully connect and traverse the API using WCFStorm however cannot seem to construct the header data correctly in order to authenticate from SoapClient. A working WCF request would be as follows:

<MyMethod>
  <OutgoingHeaders attr0="MsgHeaderArray" isNull="false">
    <MsgHeaderArray0>
      <Name>ApiKey</Name>
      <Namespace>http://www.service.com/namespace</Namespace>
      <ItemType>System.String</ItemType>
      <Value>ABC123</Value>
      <Direction>Outgoing</Direction>
    </MsgHeaderArray0>
  </OutgoingHeaders>
  <MethodParameters>
    <colour>Red</colour>
    <size>Large</size>
  </MethodParameters>
</MyMethod>

Open in new window


The code I'm using to connect to the api and call the method is:

$params = array(
  'colour' => 'Red', 
  'size' => 'Large'
);
      
$service = new SoapClient('http://www.service.com/service.svc?wsdl');
$header = new SoapHeader('http://www.service.com/namespace', 'ApiKey', 'ABC123', FALSE);
$service->__setSoapHeaders(array($header));
    
 $service->MyMethod($params);

Open in new window


However I'm getting an access denied error, I'm guessing because SoapHeader isn't corrently formatted?

SoapFault: Access is denied. in SoapClient->__call()

Open in new window


Thank you for any help you can provide.
0
Mr_Splash
Asked:
Mr_Splash
  • 4
  • 2
1 Solution
 
Amar BardoliwalaCommented:
Hello Mr_Splash,

Looking at your code, it seems fine.

Seems that Direction is missing in your request header.

Otherwise, it seems fine.

Might be problem with wrong api key.

Have you checked it?

Look at following pages for more help on php soap

http://www.php.net/manual/en/soapheader.soapheader.php

http://stackoverflow.com/questions/589228/sending-a-soap-header-with-a-wsdl-soap-request-with-php

http://www.trachtenberg.com/talks/dirtysecretssoap.pdf

Hope this will help you.

Thank You.

Amar.

0
 
Mr_SplashAuthor Commented:
Thanks amar but I can confirm the api is correct as I can connect through a WCF client. The issue is passing the equivalent as SOAP.
0
 
Amar BardoliwalaCommented:
Hello Mr_Splash,

Did you try to look at links above?

There are some examples given on that about how to use SOAP with PHP

Thank You.

Amar.
0
Threat Trends for MSPs to Watch

See the findings.
Despite its humble beginnings, phishing has come a long way since those first crudely constructed emails. Today, phishing sites can appear and disappear in the length of a coffee break, and it takes more than a little know-how to keep your clients secure.

 
Mr_SplashAuthor Commented:
Thanks amar, I'm familiar with using SOAP with PHP and my code looks very similar to the examples. Which is why I'm looking for help specifically with creating the header to match the WCF example..
0
 
Mr_SplashAuthor Commented:
Had to post raw SOAP through cURL in the end.
0
 
Mr_SplashAuthor Commented:
No workable solution put forward
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now