cancel
Showing results for 
Search instead for 
Did you mean: 

How do I set SOAP Headers when calling Client Proxies?

Former Member
0 Kudos

Hi all,

I'm trying to call a SalesForce Web Service from ABAP.

I've generated an Enterprise WSDL in salesforce and created my client proxy in SAP.

Salesforce requires you to login which passes a sessionId back and you then use the sessionId in subsequent calls (e.g. to create an Asset).

The login is working fine.

However I can't work out how to set the session id.

The Payload needs to look similar to the sample payload I have included below

What I'm ideally after is some sample abap to populate the soapenv:Header with the Session Id.

Or if there is a way of configuring this in the proxy or soamanager.

Regards,

John

Sample Payload

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

xmlns:urn="urn:enterprise.soap.sforce.com"

xmlns:urn1="urn:sobject.enterprise.soap.sforce.com"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<soapenv:Header>

<urn:SessionHeader>

<urn:sessionId>00DA0000000Ja5a!ARsAQHn8yif2c.T31jd3.c.5wCQbPWU1QNoJgClqbPEhm5EEQHn1Iu9NcxTYOXE6ojAP_Y.svsy_Ai14DCubjmupD7CTQfjw</urn:sessionId>

</urn:SessionHeader>

</soapenv:Header>

<soapenv:Body>

<urn:create>

<!Zero or more repetitions:>

<urn:sObjects xsi:type="urn:Asset"

xmlns:ns3="urn:sobject.enterprise.soap.sforce.com">

<urn:Account xsi:type="urn:Account">

<urn:Id xsi:nil="true"/>

<urn:SAP_Sold_To_Bill_To_Account__c>Xerox Corporation</urn:SAP_Sold_To_Bill_To_Account__c>

</urn:Account>

<urn:Name>JWSOAPTEST Asset2</urn:Name>

<urn:IsCompetitorProduct>0</urn:IsCompetitorProduct>

<urn:Description>Asset Description</urn:Description>

<urn:InstallDate>2010-07-29</urn:InstallDate>

<urn:Price>1.00</urn:Price>

<urn:Product2 xsi:type="urn:Product2">

<urn:Id xsi:nil="true"/>

<urn:Name>GenWatt Diesel 1000kW</urn:Name>

</urn:Product2>

<urn:ProductCode></urn:ProductCode>

<urn:ProductDescription></urn:ProductDescription>

<urn:ProductFamily></urn:ProductFamily>

<urn:Quantity>1</urn:Quantity>

<urn:SerialNumber>JWSOAPSER2</urn:SerialNumber>

<urn:Status>Shipped</urn:Status>

<urn:UsageEndDate>2010-07-29</urn:UsageEndDate>

</urn:sObjects>

</urn:create>

</soapenv:Body>

</soapenv:Envelope>

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

You need to use WS_HEADER to access parameters.

you can see source code exmple here:

SAP help documentation here: http://help.sap.com/saphelp_nwpi71/helpdata/en/51/d5cd16235e4643ae8ec92395c4ad97/frameset.htm

Regards,

Gourav

Answers (1)

Answers (1)

Former Member
0 Kudos

Gourav,

Thank you so much, that was exactly what I was after.

Regards,

John

Former Member
0 Kudos

Hi John

I have the same problem like you. Iu2019m able to do the login.

Then I use the WS_HEADER as explained in .

TRY.

  • Additional Header:

CONCATENATE '<soapenv:Header>'

'<urn:SessionHeader>'

'<urn:sessionId>' login_output-result-session_id '</urn:sessionId>'

'</urn:SessionHeader>'

'</soapenv:Header>'

INTO l_string.

  • convert to xstring

l_xstring = cl_proxy_service=>cstring2xstring( l_string ).

ws_header ?= obj_add->get_protocol('IF_WSPROTOCOL_WS_HEADER').

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( ).

namespace = 'urn:partner.soap.sforce.com'.

IF NOT xml_element IS INITIAL.

ENDIF.

  • get WS_HEADER protocol

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.

When Iu2019m calling the query-method, I get a Parser Error (CX_SXML_PARSE_ERROR). I think itu2019s from the Header.

Could you show me how you have done this part of coding?

Thanks,

Daniel

Former Member
0 Kudos

Hi Daniel,

You also need to define prefix "urn" in header, edit header and then test . If still facing problem then please see log for error detail.

Example:

'<urn:SessionHeader xmlns:urn="yournamespace"> '

Regards,

Gourav