Sometimes we com across a situation when we are trying to consume a non-SAP web service and they ask to set us a few parameters in SOAP-Headers.
Before I discuss the solution just mentioning the assumptions being made here:
1. The developer knows how to create a consumer proxy using SE80
2. The developer knows how to create Logical Port for consumer proxy in SOAMANAGER
With above ground rules established lets get to solving our problem of manipulating SOAP-header at runtime. SAP provides us with an Interface IF_WSPROTOCOL which allows ABAPers to manipulate the proxy runtime, details on this interface are available here : http://help.sap.com/saphelp_nw73ehp1/helpdata/en/51/d5cd16235e4643ae8ec92395c4ad97/content.htm
The interface provides us a protocol called WS_HEADER which can be used to add info to SOAP header while consuming services. Coming to the coding part, in your calling program once we instantiate the CLIENT PROXY, we can access WS_HEADER by using GET_PROTOCOL method of CLIENT PROXY, this will provide you with a handle to WS_HEADER, now comes the tricky part as to how add your info to SOAP-Header, for this WS_HEADER has a method called SET_REQUEST_HEADER , but the issue is this method only accepts data in XML DOM format, so to solve this you would need to use the iXML factory.
data: client_proxy type ref to Zco_your_consumer_proxy,
ws_header type ref to if_wsprotocol_ws_header,
system_fault type ref to cx_ai_system_fault,
name type string,
namespace type string.
data: obj_ixml type ref to if_ixml,
obj_ixml_factory type ref to if_ixml_stream_factory,
obj_ixml_ostream type ref to if_ixml_ostream,
obj_ixml_istream type ref to if_ixml_istream,
obj_parser type ref to if_ixml_parser,
w_error type i.
data: 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: lw_cstring type string,
l_xstring type xstring,
l_string type string.
* create instance
create object client_proxy
exporting
logical_port_name = 'ZLP'.
* get WS_HEADER protocol
ws_header ?= client_proxy->get_protocol( if_wsprotocol=>ws_header ).
* l_string contains XML data
if not l_string is initial.
* create iXML DOM document from XML
obj_ixml = cl_ixml=>create( ).
obj_ixml_factory = obj_ixml->create_stream_factory( ).
obj_ixml_istream = obj_ixml_factory->create_istream_string( l_string ).
xml_document = obj_ixml->create_document( ).
obj_parser = obj_ixml->create_parser(
stream_factory = obj_ixml_factory
istream = obj_ixml_istream
document = xml_document ).
w_error = obj_parser->parse( ).
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.
* Now call proxy method
call method client_proxy->intended_service_operation
exporting
input = request_object
importing
output = response_object.
Hope this is useful.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 |