Skip to Content
avatar image
Former Member

Using cl_http_client for calling WSDL(URL) method

Hi Experts,

I am trying to consume WSDL using  class CL_HTTP_CLIENT, may be I am missing some thing in below code, could any one please correct what I am missing? , I am not pretty sure how to use methods but written below code for reference written using other codes in SDN

Actually I need to pass multiple parameters to SubmitEx2 method at a time,

is there any best example with WSDL and code for regarding methods to use while calling URL and parameters to pass...,

like any WSDL like Currency Convertor in http://www.webservicex.net     

my code for your information :

DATA: http_client TYPE REF TO if_http_client,
host_str TYPE string VALUE 'X.y.z.a,
    service_str TYPE string,
    path TYPE string VALUE 'itpserver/itpserver.asmx',
    errortext TYPE string. "used for error handlingDATA  : wf_string1 TYPE string,

         lw_input TYPE zcrm_aia_wsdl_cpsubmit_ex2soa1,
         lw_output TYPE  zcrm_aia_wsdl_cpsubmit_ex2soap,

         lw_inputs TYPE string,
         lw_outputs TYPE  string.


*CALL METHOD cl_http_client=>create

*  EXPORTING

*    host               = host_str

*   service            = service_str

**   proxy_host         = proxy_host

**   proxy_service      = proxy_service

**   scheme             = '1'"scheme

*  IMPORTING

*    client             = http_client

*  EXCEPTIONS

*    argument_not_found = 1*    internal_error     = 2*    plugin_not_active  = 3*    OTHERS             = 4.

CALL METHOD cl_http_client=>create_by_url
  EXPORTING
    url                = 'http://x.y.z.a/itpserver/itpserver.asmx'

*   proxy_host         =

*   proxy_service      =

*   ssl_id             =*   sap_username       =*   sap_client         =
  IMPORTING
    client             = http_client
  EXCEPTIONS
    argument_not_found = 1
    plugin_not_active  = 2
    internal_error     = 3
    OTHERS             = 4.IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

CALL METHOD http_client->request->set_header_field
  EXPORTING
    name  = '~request_method'
    value = 'POST'.CALL METHOD http_client->request->set_header_field
  EXPORTING
    name  = '~server_protocol'
    value = 'HTTP/1.1'.CALL METHOD http_client->request->set_header_field
  EXPORTING
    name  = '~request_uri'
    value = '/itpserver/itpserver.asmx'.

CALL METHOD http_client->request->set_header_field
  EXPORTING
    name  = 'Content-Type'
    value = 'application/soap+xml; charset=utf-8'."'text/xml; charset=utf-8'.

CALL METHOD http_client->request->set_header_field
  EXPORTING
    name  = 'Content-Length'
    value = '19000'."txlen.CALL METHOD http_client->request->set_header_field
  EXPORTING
    name  = 'SOAPAction'
    value = 'http://www.aia-itp.com/itpserver/wsdl/SubmitEx2'.


CONCATENATE'<?xml version="1.0" encoding="utf-8"?>''<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"''xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
' <soap:Body>'
    '<service xmlns="http://www.aia-itp.com/itpserver/wsdl">generatedocument</service>'
    '<parms xmlns="http://www.aia-itp.com/itpserver/wsdl">'
      '<string>Quote</string>'
      '<string></string>'
    '</parms>'
    '<inKeyValues xmlns="http://www.aia-itp.com/itpserver/wsdl">'
      '<KeyValue>'
        '<key></key>'
        '<value></value>'
      '</KeyValue>'
      '<KeyValue>'
        '<key></key>'
        '<value></value>'
      '</KeyValue>'
    '</inKeyValues>'
    '<inDocuments xmlns="http://www.aia-itp.com/itpserver/wsdl">'
      '<Doc>'
        '<id>xmldoc</id>'
        '<content></content>'
      '</Doc>'
      '<Doc>'
        '<id>xmldoc</id>'
        '<content></content>'
      '</Doc>'
    '</inDocuments>'
    '<sessionID xmlns="http://www.aia-itp.com/itpserver/wsdl"></sessionID>'
    '<jobID xmlns="http://www.aia-itp.com/itpserver/wsdl"></jobID>''</soap:Body>''</soap:Envelope>'
INTO wf_string1.
CALL METHOD http_client->request->set_cdata
  EXPORTING
    data   = wf_string1*   offset = 0
    length = '19000'.

CALL METHOD http_client->send
  EXCEPTIONS
    http_communication_failure = 1
    http_invalid_state         = 2.

CALL METHOD http_client->receive
  EXCEPTIONS
    http_communication_failure = 1
    http_invalid_state         = 2
    http_processing_failed     = 3.CLEAR wf_string1 .

wf_string1 = http_client->response->get_cdata( ).  

Here how to pass data using 'POST' method of HTTP and how to get results using HTTPs 'GET', how to use these two?

Thanks,

VijInd

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Feb 12, 2013 at 09:14 PM

    Hi Vijlnd,

    is there any specific reason why you want to call a web service using CL_HTTP_CLIENT?

    Instead of manually crafting the XML and the request it would be much easier to use the web service infrastructure provide by ABAP and NW. You can, for example, simply create a ABAP proxy from a WSDL. Invoking the web service is then as easy as calling a method.

    See the following link for some information regarding the ABAP web service capabilities:

    http://help.sap.com/saphelp_dm40/helpdata/en/9b/dad1ae3908ee44a5caf57e10918be9/content.htm

    Christian

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Vij,

      I'm facing a similar issue. Could you consume the WSDL via http client ? Can you share your last version of your code ?

      Thanks in advance

      Have a nice day.