wsdl地址或者接口地址中有多个方法(operation)
如下是soapui测试的例子,wsdl地址下包含多个operation,但是现在我想用http的方式,只做getKnowledgePartsDatabase方法。
因为soap的调用是直接传的xml,所以需要做两个strans来把数据转换一下。这里接口用的是hashmap,所以在abap转换xml的只需要传一个内表,转换里循环处理一下就可以了。如下:蓝框内为全部soapui的xml数据,只是将key value换成了loop
到这里就可以做建单的转换测试了。
转过的xml自带了sap的Envelope和header,所以程序里给处理调,没想其他方法,如果有,可以推荐下,谢谢!
然后是写返回的转换,类型的xml
然后输数据处理
REPORT zcrm_call_strans. TYPES:BEGIN OF ty_item, id TYPE string, name TYPE string, END OF ty_item, BEGIN OF ty_back, json TYPE string, END OF ty_back, BEGIN OF ty_list, exportmodel TYPE string, parttitle TYPE string, docid TYPE string, customermodel TYPE string, END OF ty_list. DATA:BEGIN OF gw_res, result TYPE string, data TYPE TABLE OF ty_list, issucces TYPE string, END OF gw_res. DATA:gt_item TYPE TABLE OF ty_item, gw_item LIKE LINE OF gt_item, gv_string TYPE string, gx_service TYPE xstring. DATA: lo_http_client TYPE REF TO if_http_client, lv_service TYPE string, lv_request TYPE string, lv_len TYPE i, lv_result TYPE string, lx_result TYPE xstring, gv_result TYPE string, lv_code TYPE i, lv_reason TYPE string, gw_back TYPE ty_back, lo_ixml TYPE REF TO if_ixml, lo_streamfactory TYPE REF TO if_ixml_stream_factory, lo_istream TYPE REF TO if_ixml_istream, lo_document TYPE REF TO if_ixml_document, conv TYPE REF TO cl_abap_conv_in_ce. gw_item-id = 'LoginName'. gw_item-name = '2023102317301530::MjAwNjI1'. APPEND gw_item TO gt_item. gw_item-id = 'CustomerModel'. gw_item-name = 'HR6BF121B'. APPEND gw_item TO gt_item. CALL TRANSFORMATION zcrm_partsservice_req SOURCE root = gt_item RESULT XML gv_string. lv_len = strlen( gv_string ). lv_len = lv_len - 116. gv_string = gv_string+116(lv_len). CONCATENATE '<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:' 'soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:crm="http://crmsoap.trs.com">' gv_string INTO gv_string. *CHECK 1 = 2. lv_service = 'http://xxxxxxxxxxxx/ekp/services/trsekp:HisenseEKPPartsService'. CALL FUNCTION 'ECATT_CONV_STRING_TO_XSTRING' EXPORTING im_string = gv_string * IM_ENCODING = IMPORTING ex_xstring = gx_service. * lv_len = strlen( gv_string ). lv_len = xstrlen( gx_service ). cl_http_client=>create_by_url( EXPORTING url = lv_service IMPORTING client = lo_http_client EXCEPTIONS argument_not_found = 1 plugin_not_active = 2 internal_error = 3 OTHERS = 4 ). lo_http_client->request->if_http_entity~set_header_field( name = 'SOAPAction' value = '#getKnowledgePartsDatabase' ). lo_http_client->request->set_method( if_http_request=>co_request_method_post ). lo_http_client->request->if_http_entity~set_content_type( content_type = 'text/html' ). lo_http_client->response->if_http_entity~set_content_type( content_type = 'text/xml;charset=utf-8' ). lo_http_client->response->if_http_entity~set_header_field( name = '~server_protocol' value = 'HTTP/1.1' ). lo_http_client->response->if_http_entity~set_header_field( name = 'Transfer-Encoding' value = 'chunked' ). CALL METHOD lo_http_client->request->set_data EXPORTING data = gx_service offset = 0 length = lv_len. lo_http_client->send( EXCEPTIONS http_communication_failure = 1 http_invalid_state = 2 ). lo_http_client->receive( EXCEPTIONS http_communication_failure = 1 http_invalid_state = 2 http_processing_failed = 3 ). CLEAR lv_result . lx_result = lo_http_client->response->get_data( ). CLEAR: lv_code,lv_reason. lo_http_client->response->get_status( IMPORTING code = lv_code reason = lv_reason ). CALL METHOD lo_http_client->close. CHECK lx_result IS NOT INITIAL. CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING' EXPORTING im_xstring = lx_result im_encoding = 'UTF-8' IMPORTING ex_string = gv_result. REPLACE ALL OCCURRENCES OF '"' IN gv_result WITH '"'. CALL TRANSFORMATION zcrm_partsservice_rep SOURCE XML lx_result RESULT root = gw_back. zprocessjson=>deserialize( EXPORTING json = gw_back-json CHANGING data = gw_res ). CHECK 1 = 1.
^_^很多人都把资料锁进了note里,以后还怎么百度呢^_^