cancel
Showing results for 
Search instead for 
Did you mean: 

Call API returns code 500

hagit
Active Participant
0 Kudos
397

Hello experts,

 

I try to access a service via ABAP code. The status code which is returned is 500 . The error message is: 'The message with Action '' can not be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).'

My code is

REPORT ztry.
DATA: im_url TYPE string
     ,lo_client TYPE REF TO if_http_client
     ,lv_send2url_xstring   TYPE xstring
     ,lv_send2url_string TYPE string
     .
im_url =       'https://xxxx/SOAP'.
cl_http_client=>create_by_url(
EXPORTING
  url                = im_url
IMPORTING
  client             = lo_client
EXCEPTIONS
  argument_not_found = 1
  plugin_not_active  = 2
  internal_error     = 3
  ).

IF sy-subrc IS NOT INITIAL.
  MESSAGE 'err' TYPE 'I'.
ENDIF.
*   "STEP-3 :  SET HTTP HEADERS
 CALL METHOD Lo_CLIENT->REQUEST->SET_HEADER_FIELD
      EXPORTING NAME  = 'Accept'
                VALUE = 'text/xml'.

 CALL METHOD Lo_CLIENT->REQUEST->SET_HEADER_FIELD
    EXPORTING NAME  =  '~request_method' 
*               VALUE = 'GET' .
               VALUE = 'POST' .

 CALL METHOD Lo_CLIENT->REQUEST->SET_CONTENT_TYPE
    EXPORTING CONTENT_TYPE  = 'text/xml' .
lv_send2url_string =
'<soapenv:Envelope xmlns:soapenv="http://xxx/" xmlns:ns="http://xxx">' &&
'<soapenv:Header/>' &&
'<soapenv:Body>' &&
'<ns:method_name>' &&
'<ns:sSecno>xxx</ns:sSecno>' &&
'<ns:sPassword><xxx></ns:sPassword>' &&
'<ns:sOptionalID></ns:sOptionalID>' &&
'<ns:sTimeFrom>2024-11-01T12:00:00</ns:sTimeFrom>' &&
'<!--Optional:-->' &&
'<ns:sTimeTo>2023-11-07T12:00:00</ns:sTimeTo>' &&
'<ns:sMode></ns:sMode>' &&
'</ns:IMTimeStampSearch>' &&
'</soapenv:Body>' &&
'</soapenv:Envelope>' .

IF lv_send2url_string IS NOT INITIAL.
  CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
    EXPORTING
      text   = lv_send2url_string
    IMPORTING
      buffer = lv_send2url_xstring
    EXCEPTIONS
      failed = 1
      OTHERS = 2.

  CALL METHOD lo_client->request->set_data
    EXPORTING
      data = lv_send2url_xstring.
* STEP-5 :  SEND HTTP REQUEST
CALL METHOD lo_client->send
  EXCEPTIONS
    http_communication_failure = 1
    http_invalid_state         = 2.


* STEP-6 :  GET HTTP RESPONSE
CALL METHOD lo_client->receive
  EXCEPTIONS
    http_communication_failure = 1
    http_invalid_state         = 2
    http_processing_failed     = 3.


CALL METHOD lo_client->response->get_status
  IMPORTING
    code = DATA(l_status_code).


IF l_status_code = 200. "success
ENDIF.

CALL METHOD lo_client->response->get_cdata
  RECEIVING
    data = DATA(l_response_data).
lo_client->close( ).

Do you know what is the problem?

 Thanks in advanced

Hagit

 

Accepted Solutions (1)

Accepted Solutions (1)

Ryan-Crosby
Active Contributor

Sounds like you are missing a SOAPAction header, so the receiving system is unable to identify which action to take.

 

Regards,

Ryan Crosby

hagit
Active Participant
@Ryan-Crosby Thank you for your answer. You are right. I add SoapAction and got status code 200 (success).

Answers (1)

Answers (1)

hagit
Active Participant
0 Kudos

@Sandra_Rossi  thankyou for your answer.

I will try and let you know the results.