Skip to Content
avatar image
Former Member

Consume web service in ABAP proxy with SOAP header

Hi Thomas ,

I am trying to consume web service in ABAP . I have followed the procedure from one of your web blog <a href="/people/thomas.jung3/blog/2004/11/17/bsp-a-developers-journal-part-xiv--consuming-webservices-with-abap a Developer's Journal Part XIV - Consuming WebServices with ABAP</a> . (640 release).

I need to pass SOAP header along with SOAP body. As you mentioned I have used if_wsprotocol_ws_header interface to pass header but it is still failing.

Please see below code and please give some direction to fix the issue.

1.Create ABAP proxy for WSDL (http://ws.strikeiron.com/SwanandMokashi/StockQuotes?WSDL). It has created structures only for SOAP body.

2.Create Logical port

3.Create following program to call proxy

REPORT zproxy.

DATA: ref_stock TYPE REF TO zzco_stock_quotes_soap ,

ws_header TYPE REF TO if_wsprotocol_ws_header,

name TYPE string,

namespace TYPE string.

TRY.

CREATE OBJECT ref_stock

.

  • get WS_HEADER protocol

ws_header ?= ref_stock->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:

CONCATENATE

'<soap:Header>'

' http://ws.strikeiron.com">'

'<s1:RegisteredUser>'

' raj_raj431@yahoo.com '

'<s1:Password>aaaaaaaa</s1:Password>'

'</s1:RegisteredUser></s1:LicenseInfo>'

'</soap: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 = 'http://swanandmokashi.com' . "xml_element->get_namespace_uri( ).

IF NOT xml_element IS INITIAL.

ENDIF.

ws_header->set_request_header(

name = name

namespace = namespace

dom = xml_element ).

xml_element ?= xml_element->get_next( ).

ENDWHILE.

ENDIF.

ENDIF.

CATCH cx_ai_system_fault .

ENDTRY.

***************************************************************************

*Call soap body using abap proxy class.

DATA: get_quotes TYPE zzget_quotes_soap_out .

DATA: get_quotes1 TYPE zzget_quotes_soap_in .

get_quotes1-quote_ticker = 'GE'.

TRY.

CALL METHOD ref_stock->get_stock_quotes

EXPORTING

get_quotes1 = get_quotes1

IMPORTING

get_quotes = get_quotes.

CATCH cx_ai_system_fault .

CATCH cx_ai_application_fault .

ENDTRY.

4.It is throwing cx_ai_system_fault error.

SOAP details:

Input:

<?xml version="1.0" encoding="utf-8"?>

http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xmlns:s=" http://www.w3.org/2001/XMLSchema" xmlns:enc=" http://schemas.xmlsoap.org/soap/encoding" >

<soap:Header>

http://ws.strikeiron.com">

<s1:RegisteredUser>

raj_raj431@yahoo.com

<s1:Password>aaaaaaaa</s1:Password>

</s1:RegisteredUser>

</s1:LicenseInfo>

</soap:Header>

<soap:Body>

http://swanandmokashi.com">

<tns:QuoteTicker>GE</tns:QuoteTicker>

</tns:GetQuotes>

</soap:Body>

</soap:Envelope>

Thanks,

Kavitha.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Dec 20, 2006 at 02:56 PM

    The processing of the SOAP header itself appears correct. I have to wonder after reading the rest of the threads if there is some other problem with the Web Service. Have you tried activating the trace to get more details out of the Web Service call. Perhaps your headers are technically correct, but the information in them is not.

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 19, 2006 at 10:45 AM

    whats the errortext

    Regards

    Raja

    Add comment
    10|10000 characters needed characters exceeded