Difference between SOAP & HTTPRequest Headers?

Hello,

I have a webservice I need to call which contains a <soap12:Header> element within its XML.

<soap12:Header>
    <ServiceAuthHeader xmlns="http://dummyNameForExpertsExc">
      <User>string</User>
      <Password>string</Password>
    </ServiceAuthHeader>
  </soap12:Header>

In calling the webservice I will be doing so using the HttpRequest and HttpResponse apex classes.

the HttpRequest class has a method called setHeader.

In examples I have seen it is used to set attributes such as content type in the following

HttpRequest req = new HttpRequest();
req.setEndpoint('http://dummyNameForBlogPost.com/serviceTest.asmx ');
req.setMethod('POST');
req.setHeader('Content-Type', 'application/soap+xml');
req.setTimeout(60000);

There is a setBody method for HttpRequest also.

Should my SOAP Header actually go with the rest of my XML in  the setBody method?
speedygonzalezAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

speedygonzalezAuthor Commented:
Sorry accidently saved before finishing my question.

My question is

Should my SOAP Header actually go with the rest of my XML in  the setBody method? or should it be set in the HTTPRequest.setHeader() method?

This has really confused me.

Thanks.
0
Holger101497Commented:
Yes, the SOAP header is part of the "payload". Both soap:Header and soap:Body are wrapped in an element called soap:Envelope. You can find a very quick example at http://en.wikipedia.org/wiki/SOAP#Example_message

 
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
  <soap:Header>
  </soap:Header>
  <soap:Body>
    <m:GetStockPrice xmlns:m="http://www.example.org/stock">
      <m:StockName>IBM</m:StockName>
    </m:GetStockPrice>
  </soap:Body>
</soap:Envelope>

Open in new window


The "HttpRequest" knows nothing about soap-specific features and the setHeader()-method will simply set the HTTP-HEADERS. (to make this a bit more confusing, you'll probably have to set an http-header called soap-action :-))

Hope that helps, let me know if you need more info.

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
speedygonzalezAuthor Commented:
Thanks. This answer is very useful!
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
Web Services

From novice to tech pro — start learning today.