Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Web Services Security using ABAP Proxies

Former Member
0 Kudos

Hello everyone,

I'm having a problem setting the security information in a SOAP header using a generated ABAP Client Proxy to consume a .Net web service. I'm on a WAS 6.40 system.

The WSDL has a security header attribute in it so I need to set the data in the SOAP header.

<soap:Header>

<SecurityHeader xmlns="http://Test.com/TestService/">

<Username>string</Username>

<Password>string</Password>

</SecurityHeader>

</soap:Header>

Here are the steps that I have taken to set the security values.

1) Created the client proxy from the WSDL and turned on Basic Authentication on the Preconfiguration tab.

2) Created an outbound set user name profile in transaction WSPROFILE with the appropriate username and password.

3) Added the profile to the default port in transaction LPCONFIG as an outbound under the WS Security section of the screen.

However, when I run my application and trace the client call from SICF I only see the TRACE information in my SOAP header nothing about security.

I'm not sure what I'm doing wrong, so any help would be appreciated.

Thanks,

Jeff

1 ACCEPTED SOLUTION

Former Member

Jeff, I have the same problem.Did you solve it?

Regards, Marko.

9 REPLIES 9

Former Member

Jeff, I have the same problem.Did you solve it?

Regards, Marko.

0 Kudos

Hi, Jeff,

look at the documentation on interface IF_WSPROTOCOL_WS_HEADER. There you can find an example code on how to add SOAP header.

Regards, Marko.

0 Kudos

Hi Marko,

I am also having the same problem. From web service I have created ABAP proxy and soap header is missing (It was created structure only for SOAP body). I have suggested to use IF_WSPROTOCOL_WS_HEADER interface to get soap header part from soap envalop.It has no documentation in English.Can you please send sample code or any direction to implement soap header.

Thomas,

I n one of your web log you mentioned about IF_WSPROTOCOL_WS_HEADER interface .Could you please let me know How I can use it in my wizard genarated ABAP proxy class?

Thanks,

Kavitha.

0 Kudos

Have a look at this section of the online help:

http://help.sap.com/saphelp_nw2004s/helpdata/en/51/d5cd16235e4643ae8ec92395c4ad97/frameset.htm

You can use the example there - except instead of the payload you want to query and request the WS_PROTOCOL. Change:

lo_payload_protocol ?=

lo_clientProxy->get_protocol( if_wsprotocol=>payload ).

to

data lo_header type ref to if_wsprotocol_ws_header.

lo_header ?= lo_clientproxy->get_protocol( if_wsprotocol=>ws_header ).

or here is a complete example for the in-system help:

Description

Using this proxy protocol, you can set additional SOAP header fields for an outbound (client) request message or read them for an outbound response message.

Only proxies are available for the WS outbound (client)

Use

The following methods are available:

SET_REQUEST_HEADER

GET_RESPONSE_HEADER

Example

*&---------------------------------------------------------------------*
*& 
*& ---------------------------------------------------------------------*
*& 
*&
*&---------------------------------------------------------------------*
************************************************************************
* Report demonstrates use of WS_HEADER protocol
************************************************************************

REPORT  docu_proto_ws_header.

DATA: interface TYPE REF TO co_sxidag_fsa_query,
      request TYPE sxidag_fsa_query_mt,
      response TYPE sxidag_fsa_response_mt,
      ws_header TYPE REF TO if_wsprotocol_ws_header,
      system_fault TYPE REF TO cx_ai_system_fault,
      flight_not_found TYPE REF TO cx_sxidag_flight_not_found,
      name TYPE string,
      namespace TYPE string.



* fill request data
request-flight_seat_availability_query-flight_id-airline_id = 'LH'.
request-flight_seat_availability_query-flight_id-connection_id =400.
request-flight_seat_availability_query-flight_id-flight_date ='20030524'.

TRY.


*   create instance
    CREATE OBJECT interface.

*   get WS_HEADER protocol
    ws_header ?= interface-> get_protocol('IF_WSPROTOCOL_WS_HEADER').

***************************************************************************
*   set somehow header as iXML-DOM tree
    DATA: ixml TYPE REF TO if_ixml,
          xml_document TYPE REF TO if_ixml_document,
          xml_root TYPE REF TO if_ixml_element,
          xml_element TYPE REF TO if_ixml_element,
          xml_node TYPE REF TO if_ixml_node.
    DATA l_xstring        TYPE xstring.
    DATA l_string         TYPE string.
    FIELD-SYMBOLS <fs_xstring> TYPE xstring.

*   Additional Header:
*   here we have 2 header elements as DOM fragment, eb:MessageHeaderand wsse:Security

    CONCATENATE
'<SOAP-ENV:Header>'
'< eb:MessageHeader eb:version="1.0" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
' xmlns:eb="http://www.ebxml.org/namespaces/messageHeader" '
'  xmlns:xsd="http://www.w3.org/1999/XMLSchema"> '
' < eb:ConversationId>NULL</eb:ConversationId> '
' < eb:From>'
' < eb:PartyId type="urn:x12.org:IO5:01">99999</eb:PartyId> '
'   </eb:From> '
' < eb:To> '
' < eb:PartyId type="urn:x12.org:IO5:01">123123</eb:PartyId> '
'   </eb:To> '
' < eb:CPAId>IPCC</eb:CPAId> '
' < eb:Service eb:type="OTA">SabreCommand</eb:Service> '
' < eb:Action>SabreCommandLLSRQ</eb:Action> ' 
' < eb:MessageData> '
' < eb:MessageId>mid:20001209-133003-2333@ clientofsabre.com< /eb:MessageId> '
' < eb:Timestamp>2001-02-15T11:15:12Z</eb:Timestamp>  '
' < eb:TimeToLive>2001-02-15T11:15:12Z</eb:TimeToLive> '
'     </eb:MessageData> '
'   </eb:MessageHeader> '
'   <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext" '
'     xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/12/utility"> '
'     <wsse:UsernameToken> '
'       <wsse:Username>12345</wsse:Username> '
'       <wsse:Password>ABC123</wsse:Password> '
'       <Organization>NM9A</Organization> '
'       <Domain>DEFAULT</Domain> '
'     </wsse:UsernameToken>'
'   </wsse:Security> '
' </SOAP-ENV: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.


***************************************************************************
*   common coding....

*   call outbound
    CALL METHOD interface->execute_synchronous
       EXPORTING
        output = request
       IMPORTING
        input  = response.

***************************************************************************
*   if supported by WebService, -
*   here additional response header elements can be read
*   in this example we assume that the server has set the same header fields in
*   the response message.
    xml_element =   ws_header-> get_response_header(
                            name = 'MessageHeader'
                           namespace = 'http://www.ebxml.org/namespaces/messageHeader' ).

    IF NOT xml_element IS INITIAL.
      PERFORM show_xml
         USING xml_element.
    ENDIF.

*   etc.....


  CATCH cx_ai_system_fault INTO system_fault.
    WRITE:/ 'System Fault'(sye).
    WRITE:/ system_fault->errortext.
    EXIT.
  CATCH cx_sxidag_flight_not_found INTO flight_not_found .
    WRITE:/ 'Requested flight not found'(fnf).
    EXIT.
  CATCH cx_ai_application_fault .
    WRITE:/ 'Application fault'(apf).
    EXIT.
ENDTRY.


* show Result
WRITE:/ 'Availability Check Result'(res).
SKIP.
WRITE:/ 'Economy Class:'(ecc).
WRITE:/3 'Seats total:'(tot),
    response-flight_seat_availability_resp-economy_max_seats.
WRITE:/3 'Seats Free:'(fre),
     response-flight_seat_availability_resp-economy_free_seats.
SKIP.
WRITE:/ 'Business Class:'(bsc).
WRITE:/3 text-tot,
    response-flight_seat_availability_resp-business_max_seats.
WRITE:/3 text-fre,
     response-flight_seat_availability_resp-business_free_seats.
SKIP.
WRITE:/ 'First Class:'(ftc).
WRITE:/3 text-tot,
    response-flight_seat_availability_resp-first_max_seats.
WRITE:/3 text-fre,
    response-flight_seat_availability_resp-first_free_seats.


*& --------------------------------------------------------------------*
*&           Form  show_Xml
*& --------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
*         --> ELEMENT     text
*---------------------------------------------------------------------*
FORM show_xml
  USING element TYPE REF TO if_ixml_element.
  DATA:
      ixml_factory TYPE REF TO if_ixml,
      stream   TYPE REF TO if_ixml_ostream,
      encoding TYPE REF TO if_ixml_encoding,
      stream_factory TYPE REF TO if_ixml_stream_factory.

  DATA: l_x TYPE xstring, l_c TYPE string.

  ixml_factory =  cl_ixml=>create( ).
  stream_factory  = ixml_factory->create_stream_factory( ).
  encoding = ixml_factory->create_encoding( character_set = 'UTF-8'
                                      byte_order    = 0 ).
  stream = stream_factory->create_ostream_xstring( string = l_x ).
  stream->set_encoding( encoding = encoding ).

  element->render( ostream = stream ).

  cl_proxy_service=>show_xml_document( xml = l_x ).

ENDFORM.                     "show_Xml

0 Kudos

Hi Thomas,

Thank you for the response. I have followed the steps as you mention but it is still throughing an error. I have created new thread for this issue .

Could you please look into it?

Thanks,

Kavitha.

0 Kudos

Hello everyone,

I am trying to consume a Web Service from BMC Remedy (non-SAP System) in SAP Solution Manager. I have generated the required ABAP Proxy Class from the WSDL file, created a logical port along with the authentification details using SOAMANAGER and instantiated the proxy class in an ABAP Program along with the request parameters to call the service. I keep getting the error message:- SoapFaultCode: 1.

Hence; I tried calling the service using the external open Source Program: SOAPUI 3.0.1. Here I saw that the SOAP Request includes a SOAP Header, whether the authentification details are embedded. After I added these details in the Request in SOAPUI, I could test the service successfully.

Now, I went back to the SAP system and saw that the Proxy Runtime generated only the ABAP types for the SOAP Body but no parameters were created for the SOAP Header. I found in SDN that the interface for adding SOAP Header is 'if_wsprotocol_ws_header'. Unfortunately, I did not find any documentation for it. So I just tried similar to the coding example of Thomas Jung but now I get XML parsing errors.

Can someone give me a working coding example or tutorial to solve this SOAP Header Problem? I am not sure if I am calling the following method correctly?

    • CALL METHOD lo_ws_header->if_wsprotocol_ws_header~set_request_header( name = name namespace =

    • namespace dom = xml_element ).

I would be really thankful if someone out there can help me to solve this problem.

PS: Following is the SOAP Request from SOAP UI that I need to build in the SAP System:-

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:THD_Global_Interface_Ticket_V3">

<soapenv:Header>

<urn:AuthenticationInfo>

<urn:userName>?</urn:userName>

<urn:password>?</urn:password>

<!Optional:>

<urn:authentication>?</urn:authentication>

<!Optional:>

<urn:locale>?</urn:locale>

<!Optional:>

<urn:timeZone>?</urn:timeZone>

</urn:AuthenticationInfo>

</soapenv:Header>

<soapenv:Body>

<urn:OpCreate>

<urn:GI_WS_Action_LogDelta>?</urn:GI_WS_Action_LogDelta>

.....................

<urn:GI_TransferType>Create</urn:GI_TransferType>

<urn:GI_Direction>Incoming</urn:GI_Direction>

</urn:OpCreate>

</soapenv:Body>

</soapenv:Envelope>

0 Kudos

I have the same problem with the soap header.

When I try to add the header as written in the code samples above, I receive the following error.

Proxy protocol IF_WSPROTOCOL_WS_HEADER is not available.

Can anybody help me please? many thanks!

0 Kudos

I tried the example but the Concatenate to string won't hold that much.  What is wrong?

0 Kudos

I am facing the same problem.

Getting a dump with the message:

"Proxy protocol IF_WSPROTOCOL_WS_HEADER is not available." on our client's server.

However, on our internal server, it works fine.What is the SP level or Note that is required to enable this and how do we enable this?

KR