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.
LVL 3
Mr_SplashAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mr_SplashAuthor Commented:
No workable solution put forward
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.