Skip to Content
avatar image
Former Member

External Web Service Requires - WS-Security Header (calling from ABAP)

Hello,

I have created the proxy for external Web Servcie and ABAP program to trigger it This service requires header authentication, without which I get the following error:

CODE:SoapFaultCode:1

ERRORTEXT: Security Data : No WS-Security Header

I have found a thread that deals with such issue: web-services-security-using-abap-proxies

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

'<Header>'

' http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">'

'<UsernameToken Id="uuid-e55489fa6444-1">'

'<Username>User123</Username>'

' Pass123http://docs.oasis-open.org/wss/2004/01/oasis-200401-wssusername-token-profile-1.0#PasswordText">Pass123>'

'</UsernameToken>'

'</Security>'

'</Header>' into l_string.

** convert to xstring*

l_xstring = cl_proxy_service=>cstring2xstring( l_string ).

if not l_string is initial.

** create iXML DOM document from XML xstring*

call function 'SDIXML_XML_TO_DOM'

exporting

xml = l_xstring

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.

endif.

The while loop stops because xml_element ?= xml_element->get_next( ) does not retrieve the next element. And even the first element is retrieved only partially, just its name.

Does anyone know why this code does not work? Is there any other way to pass WS-Security Header.

Thanks,

Alex

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • avatar image
    Former Member
    Jan 08, 2009 at 02:50 PM

    I have done the following change to XML string:

    concatenate

    '<SOAP:Header>'

    ' http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">'

    '<wsse:UsernameToken Id="uuid-e55489fa6444-1">'

    '<wsse:Username>User123</wsse:Username>'

    ' Pass123http://docs.oasis-open.org/wss/2004/01/oasis-200401-wssusername-token-profile-1.0#PasswordText">Pass123>'

    '</wsse:UsernameToken>'

    '</wsse:Security>'

    '</SOAP:Header>' into l_string.

    Adding wsse allowed to retrieve and set the first element "Security" to header. But all following elements were ignored. The logic xml_element ?= xml_element->get_next( ) in while loop returns null.

    Any idea?

    Thanks,

    Alex

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 08, 2009 at 10:21 PM

    I was finally able to get all 4 elements Security, UsernameToken, Username and Password in WS_HEADER. Below is modified while loop logic:

    while not xml_element is initial.

    clear: name, namespace.

    name = xml_element->get_name( ).

    namespace = xml_element->get_namespace_uri( ).

    ws_header->set_request_header(

    name = name

    namespace = namespace

    dom = xml_element ).

    if name = 'Username'.

    xml_element ?= xml_element->get_next( ).

    elseif name = 'Password'.

    exit.

    else.

    xml_element ?= xml_element->get_first_child( ).

    endif.

    endwhile.

    I should not have called xml_element ?= xml_element->get_next( ). always within the while loop since UsernameToken also has children. I hardcoded the names in if statement for now, but this can be derived dynamically.

    Unfortunately, this was not the end of the issues. Now when I call the proxy, I get the following error:

    CODE: SoapFaultCode:4

    ERRORTEXT: #XML parse error.#

    Any idea why? The system is NW 7.0 SP12.

    Thanks,

    Alex

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 09, 2009 at 09:50 PM

    A bit more info.

    If I do not pass UsernameToken element, I get the error that UsernameToken is missing, but once it is passed, I can XML Parse Error. It looks like it can not interpret UsernameToken for some reason.

    Thanks,

    Alex

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 12, 2009 at 02:43 PM

    The info below is from trace file:

    XRFC> <

    XRFC> <

    XRFC> INFO 09:40:16: SOAP SESSION Protocol CL_SOAP_SESSION_PROTOCOL <

    XRFC> ->IF_SOAP_PROTOCOL~PRE_PROCESS() SOAP Session Protocol <

    XRFC> preprocessed <

    XRFC> <

    XRFC> INFO 09:40:16: SOAP Transport Binding CL_SOAP_HTTP_TPBND_ROOT <

    XRFC> ->IF_SOAP_TRANSPORT_BINDING~SEND() Try to send message ( DEST = <

    XRFC> CCTEST_AUC ,PATH = ,URL = ,SOAP Action = "runTransaction" ) <

    XRFC> <

    XRFC> INFO 09:40:16: SOAP Transport Binding CL_SOAP_HTTP_TPBND_ROOT <

    XRFC> ->IF_SOAP_TRANSPORT_BINDING~SEND() Message sent <

    XRFC> <

    XRFC> INFO 09:40:16: SOAP Transport binding CL_SOAP_HTTP_TPBND_ROOT <

    XRFC> ->IF_SOAP_TRANSPORT_BINDING~RECEIVE() Try to receive message <

    XRFC> <

    XRFC> INFO 09:40:16: SOAP HTTP Binding CL_SOAP_HTTP_TPBND_ROOT->HANDLE <

    XRFC> STATUSCODE() Received return code 500 ( Internal Server Error ) <

    XRFC> <

    XRFC> ERROR 09:40:16: SOAP Message CL_SOAP_MESSAGE->IF_SOAP_MESSAGE <

    XRFC> PART~INITFOR_DESERIALIZE() SOAP Fault Exception caught: :

    XML <

    XRFC> parse error.

    <

    XRFC> <

    I highlighted in bold where the error takes place. Did anyone experienced this?

    Thanks,

    Alex

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 13, 2009 at 02:02 PM

    Hi Abhishek,

    Thanks for your help. I saw this note before, but it was not the issue.

    I was able to fix the issue last night, it was caused by preparing WS header incorrectly. Originally, I did not use wsse prefix, and this was issue number 1. Once I added the prefix, I thought that the following code is incorrect because it was only retreiving 1 elements - UsernameToken.

    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.

    So, I added to logic to get and then set all childeren, and this was the mistake. This is what caused "XML Parse Error". UsernameToken had already all info with user name and password. Once I removed the extra logic to get all 4 elements, the client proxy began working.

    Regards,

    Alex

    Add comment
    10|10000 characters needed characters exceeded