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: 

Consume web service in ABAP proxy with SOAP header

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

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.

10 REPLIES 10

athavanraja
Active Contributor
0 Kudos

whats the errortext

Regards

Raja

0 Kudos

does this webservice works? when i tested from the tool provided in the site i am getting the following erro

Object reference not set to an instance of an object.

Regards

Raja

0 Kudos

Hi ,

Thank you for the response. Did you passed user email and password (raj_ra431@yahoo.com /aaaaaaaa) part of licenseinfo->resisteredUser along with Quoteticker GE in analyzer?

<a href="http://www.strikeiron.com/Analyzer/OnlineAnalyzer.aspx?WSDL=http://ws.strikeiron.com/SwanandMokashi/StockQuotes?WSDL">ANALYZER</a>

Thanks,

Kavitha.

0 Kudos

i tried with unregistered user with my emailid.

tried again with the info you had given and it complains of invalid user id

Raja

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

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.

0 Kudos

Hi Thomas,

Could you please let me know how to activate trace for web service call?

Thanks,

Kavitha.

0 Kudos

0 Kudos

Hi Thomas ,

I am facing similar problem.

I am getting error - CX_SXML_PARSE _ERROR:SXML reader/writer exception.Error while parsing an XML stream: 'undeclared namespace prefix'. (fault location is 1 ).

Please help me in removing above error..

Regards ,

Jigar Thakkar.

0 Kudos

Hello Thomas,

I am facing this issue as well and do not have the authorization for running the trace. Is there any other way of tracking the cause of this issue.

Thanks!

Deepti

0 Kudos

Hi,

you can prevent the parse error when you put the namespace definition into a dedicated line in the XML file. Look at this thread: http://scn.sap.com/thread/3218416

Regards,

     Jan