Skip to Content

External Web Service requirement to inject WS-Security Header from ABAP

Hello Experts

I have created a consumer proxy for external Web Service and then created ABAP program to trigger the service. firstly I have tested this web service

in soap UI but it worked only after I have added the header authentication. without which I get the following error as

CODE:SoapFaultCode:1

I have found a thread that deals with such issue:

In that thread Thomas Jung gives example of the program on how to create service header. However, the following code does not work for me:


CONCATENATE

'<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>'

'<wsse:Username>sb</wsse:Username>'

'<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">epsepseps</wsse:Password>'

'</wsse:UsernameToken>'

'</wsse:Security></soapenv:Header>'

INTO lv_string.


LV_XSTRING_1 = CL_PROXY_SERVICE=>CSTRING2XSTRING( LV_STRING ).

** create ixml dom document from xml xstring

CALL FUNCTION 'SDIXML_XML_TO_DOM'

EXPORTING

XML = LV_XSTRING_1

IMPORTING

DOCUMENT = XML_DOCUMENT

EXCEPTIONS

INVALID_INPUT = 1

OTHERS = 2.


IF SY-SUBRC = 0 AND NOT XML_DOCUMENT IS INITIAL.


XML_ROOT = XML_DOCUMENT->GET_ROOT_ELEMENT( ).

XML_ELEMENT ?= XML_ROOT->GET_FIRST_CHILD( ).

* add header element by element to soap header

WHILE NOT XML_ELEMENT IS INITIAL.


NAME = XML_ELEMENT->GET_NAME( ).

NAMESPACE = XML_ELEMENT->GET_NAMESPACE_URI( ).

WS_HEADER->SET_REQUEST_HEADER( NAME = NAME NAMESPACE = NAMESPACE DOM = XML_ELEMENT ).

XML_ELEMENT ?= XML_ELEMENT->GET_NEXT( ).


ENDWHILE.


ENDIF.


for me The while loop stops because xml_element ?= xml_element->get_next( ) does not retrieve the next element. only I get the first

child values as name = security and namespae = xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd

and once I set the header for this then the loop skips.

couldn't understand why the loop skips with out the rest of the code as I referred to the rest of the blogs I have tried using get_first_child again but it gets usernametoken as name and then it gets namespace as xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd.


any help please really appreciated

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Aug 22, 2016 at 09:25 AM

    Guys anyone with some help. I am trying all the ways to get this work but I am failing.

    Regards

    s battula

    Add a comment
    10|10000 characters needed characters exceeded

    • Thanks Bhargav for the help I have tried it.

      I have fixed my issue and what I have came to know is

      XML_ELEMENT ?= XML_ELEMENT->GET_NEXT( ) only gets the security information in the first loop and it skips the loop as it has already all the info of username and password of the header.


      I have used a application fiddler which I have linked to the system proxy and logical port config of this web service consumer. and tested this web service consumer and all the log is loaded in the

      fiddler and it shows the header info completely loading to the web service.


      my issue now is the header is set in a perfect way but still my request is failing


      CALL METHOD E INTERFACE>XXXXXXX(

      EXPORTING

      INPUT = INPUT

      IMPORTING

      OUTPUT = OUTPUT

      so from the log of the fiddler I have copied the XML code and tested it in the SOAP UI. I have

      realized there is additional data sap is putting in the header level, when I have taken it off it worked on SOAP UI.

      so in order for sap to stop inserting the extra data in the header I have managed to suppress them by going to the config in the logical port config on message tab and changed them as below.


      RM Protocol: WS-RM 2005/02

      Message ID Protocol : Suppress ID Transfer

      Data transfer scope: Minimal Data Transfer

      Transfer protocol : Transfer via HTTP header

      once I have done the config as above and called the service from the zreport and saw the output it started working.


      for using fiddler u need to install it and take your user system proxy and go to web service consumer proxy on the logical port config go to transport binding and do as below.


      Name of Proxy Host: ( this is user system proxy)

      Port Number of Proxy Host : 8888 ( this is from fiddler)


      so my web service consumer started working.


      thanks

      sbattula


      r

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.