cancel
Showing results for 
Search instead for 
Did you mean: 

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

surendra_battula
Participant
0 Kudos

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

Accepted Solutions (0)

Answers (1)

Answers (1)

surendra_battula
Participant

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

Regards

s battula

Venkat_Sesha
Advisor
Advisor
0 Kudos

Hi Mr Battula,

Please check the below code corrections

1. You have to call this in the TRY and ENDTRY

2. Catch the method after the ENDWHILE as shown below.

        source_node = source_node->get_next( ).       ENDWHILE.     CATCH lcx_xml_error INTO ex.       MESSAGE ex->error TYPE 'E'.   ENDTRY.

3. You have to check the XML code is OK or not, there is a attribute C_OK in the class CL_XML_DOCUMENT_BASE make use of it and try using the GET_NODE_DATA and validate the return code.

4. Check if there is also a separator in your Source_code->get_name(). example like this '_--7E'

Let me know if you face problems

Thanks,

BG.

surendra_battula
Participant
0 Kudos

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

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