Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

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

'<s1:LicenseInfo xmlns:s1="http://ws.strikeiron.com">'

'<s1:RegisteredUser>'

'<s1:UserID>raj_raj431@yahoo.com</s1:UserID>'

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

<soap:Envelope xmlns:soap="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>

<s1:LicenseInfo xmlns:s1="http://ws.strikeiron.com">

<s1:RegisteredUser>

<s1:UserID>raj_raj431@yahoo.com</s1:UserID>

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

</s1:RegisteredUser>

</s1:LicenseInfo>

</soap:Header>

<soap:Body>

<tns:GetQuotes xmlns:tns="http://swanandmokashi.com">

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

</tns:GetQuotes>

</soap:Body>

</soap:Envelope>

Thanks,

Kavitha.

Tags:
Former Member
replied

You can setup the trace/logging levels in the Logic Port:

http://help.sap.com/saphelp_nw2004s/helpdata/en/16/285d32996b25428dc2eedf2b0eadd8/frameset.htm

1 View this answer in context
Not what you were looking for? View more on this topic or Ask a question