2

Please enlighten me\correct me on following point:

Is there any way to get response header details in exposed SOAP webservice Apex class method?

Like for expamle:

  1. For visualforce page, we can access response headers as : ApexPages.currentPage().getHeaders()

  2. For REST webservice class, we can accsess response headers with: getHeader method of RestContext.response

It will be very helpful, if you could provide any sample code example

1 Answer 1

2

Yes using inputHttpHeaders_x and outputHttpHeaders_x we can get and set the Header attribute in SOAP WSDL. Using them we can easily get cookies and other custom header.

docSample.DocSamplePort stub = new docSample.DocSamplePort();
stub.outputHttpHeaders_x = new Map<String, String>();
String input = 'This is the input string';
String output = stub.EchoString(input);

//Getting cookie header
String cookie = stub.outputHttpHeaders_x.get('Set-Cookie');

//Getting custom header
String myHeader = stub.outputHttpHeaders_x.get('My-Header');

Apex Web Services and Callouts

4
  • Hi Tushar, Thanks for Help! I tried same but i am not able access such parameters [inputHttpHeaders_x and outputHttpHeaders_x]. It will be great if you could provide any sample code example.
    – sfdcnoob
    May 31, 2018 at 17:06
  • 1
    @Tushar I guess, this will help when you consume the WSDL, not while exposing the webservice. "This section shows an example of an WSDL2Apex generated Apex method that invokes an Amazon Web Service."
    – Ysr Shk
    Jun 1, 2018 at 9:22
  • @YsrShkWe can get response as well. In the link there are two approach to get and set the headers. Jun 1, 2018 at 10:05
  • @TusharSharma - Yes. But AFAIk stub mostly generated by Wsdl2Apex parser. If possible, could you pls redirect on any sample webservice(not the consuming class, which is generated by parser), I would be delighted.
    – Ysr Shk
    Jun 1, 2018 at 11:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .