PI-based WebService release example

Source: Internet
Author: User
Tags wsdl

"Transfer from http://blog.csdn.net/yin_chuan_lang/article/details/6706816"

In recent projects, there are many interfaces, and WebService technology is one of the main implementation methods. The following is a specific instance of the project to experience the PI-based WebService release. The business scenario SAP system receives data from a peripheral interface System (Web-based e-commerce platform) in real time. Technical analysis because of the high synchronization requirements, data volume is small, the use of WebService implementation is more reasonable. example demonstrates creating a self-built table for receiving data from a postback: Tc:sproxy creates a service Interface in the implementation class based on the name of the integration group in the PI configuration, and updates to the self-built table based on the incoming XML string: Data:ls_field_data Like Zmmjyh_cdif, lt_field_data as Table of Ls_field_data, ls_zmmjyh_ht_0007 like zmmjyh_ht_0007, lt_zmmjyh_ht_0007 lik e Table of ls_zmmjyh_ht_0007, L_retcode Type I, L_fieldname type string, l_float type F. Field-symbols: &LT;FS_FIELDNAME&G T Type any, <fs_fieldvalue> type any. "Parses the XML data into the universal internal table type-pools:ixml. Types:begin of T_xml_line, data (+) type X, end of T_xml_line. Data:l_ixml type ref to If_ixml, L_streamfactory type ref to If_ixml_stream_factory, L_parser type ref to If_ixml_parser, L_istream type ref to If_ixml_istream, l_document type ref to If_ixml_document, L_node type ref to If_ixml_node, L_xmldat A type string. Data:l_elem type ref to If_ixml_element, L_root_node type ref to If_ixml_node, L_neXt_node type ref to If_ixml_node, L_name type string, L_iterator type ref to If_ixml_node_iterator. Data:l_xml_table type Table of T_xml_line, L_xml_line type T_xml_line, l_xml_table_size type I. * Creating the main IXML Factory l_ixml = Cl_ixml=>create (). * Creating a stream Factorya l_streamfactory = L_ixml->create_stream_factory (). L_istream = l_streamfactory->create_istream_string (string = input). * Creating a document l_document = L_ixml->create_document (). * Create a Parser l_parser = l_ixml->create_parser (stream_factory = l_streamfactory IStream = L_istream document = L_d ocument). * Parse The stream if L_parser->parse () NE 0. L_retcode = 0. return. endif. * Process the document if l_parser->is_dom_generating () eq ' X '. Perform process_dom tables lt_field_data using L_document. endif. *&--------------------------------------------------------------------* *& Form process_dom *&-------- ------------------------------------------------------------* Form process_dom tables P_i_zxml structure zmmjyh_cdif using document type ref to If_ixml_document. Data:node type ref to If_ixml_node, iterator type ref to If_ixml_node_iterator, Nodemap type ref to If_ixml_named_node_ma p, node_parent type ref to If_ixml_node, attr type ref to If_ixml_node, name type string, name1 type string, prefix type S Tring, value type string, indent Type I, count Type I, index type i. node? = document. Check not node is initial. If node is initial. Exit. endif. * Create a node iterator iterator = Node->create_iterator (). * Get current node node = Iterator->get_next (). * Loop over all nodes and not node is initial. Indent = Node->get_height () * 2. Indent = indent + 20. Case Node->get_type (). When If_ixml_node=>co_node_element. * Element Node name = Node->get_name (). Nodemap = Node->get_attributes (). If not Nodemap is initial. * Attributes Count = Nodemap->get_length (). Do count times. index = sy-index-1. attr = NodemAp->get_item (Index). Name = Attr->get_name (). prefix = Attr->get_namespace_prefix (). Value = Attr->get_value (). Record field name, field value P_i_zxml-fieldname = name. P_i_zxml-fieldvalue = value. Append P_i_zxml. Enddo. endif. When If_ixml_node=>co_node_text or if_ixml_node=>co_node_cdata_section. * Text Node value = Node->get_value (). Node_parent = Node->get_parent (). name1 = Node_parent->get_name (). Record field name, field value P_i_zxml-fieldname = name1. P_i_zxml-fieldvalue = value. Append P_i_zxml. Endcase. node = Iterator->get_next (). Endwhile. EndForm. "Process_dom" Prepares the data to the database update within the loop at Lt_field_data to Ls_field_data. Clear L_fieldname. Assign Ls_field_data-fieldvalue to <fs_fieldvalue>. Concatenate ' ls_zmmjyh_ht_0007-' ls_field_data-fieldname into L_fieldname. Assign (L_fieldname) to <fs_fieldname>. If <fs_fieldname> is assigned. If Ls_field_data-fieldname = ' contramountnum ' or ls_field_data-fieldname = ' applyamount '. The processing of the scientific notation in the Amount field is clear l_float. L_float = <fs_fieldvalue>. <fs_fieldname> = L_float. Else. <fs_fieldname> = <fs_fieldvalue>. endif. Else. It_return-zresult = ' 0 '. it_return-description = ' program exception, field name does not match! '. Append It_return. Return. endif. "Arrive at the end of a data if Ls_field_data-fieldname = ' Prepayid '." Append ls_zmmjyh_ht_0007 to lt_zmmjyh_ht_0007. Clear ls_zmmjyh_ht_0007. endif. Endloop. "Update to the self-built table if lines (lt_zmmjyh_ht_0007) > 0. Modify zmmjyh_ht_0007 from table lt_zmmjyh_ht_0007. If SY-SUBRC = 0. Commit work and wait. It_return-zresult = ' 1 '. It_return-description = ' Callback successful! '. Append It_return. Else. Rollback work. It_return-zresult = ' 0 '. It_return-description = ' callback failed, database update exception! '. Append It_return. endif. Else. It_return-zresult = ' 0 '. It_return-description = ' Countless data can be transmitted! '. Append It_return. endif. Pass the result back to the peripheral system, create a good transformation and then encapsulate the return value as an XML string: Data:l_xstr type xstring. Call transformation ZMMJYHMESGJDZSW Source root = it_return[] * Result XML output result XML l_xstr options xml_header = ' No '. Types:begin of Ty_bin, Bin_data (1024x768) type X, end of Ty_bin. Data:lt_bin type Table of Ty_bin. " File binary inside table Data:l_len type I. Check input is not initial. Call function ' scms_xstring_to_binary ' exporting buffer = l_xstr * append_to_table = ' importing output_length = L_len t Ables Binary_tab = Lt_bin. Call function ' scms_binary_to_string ' exporting input_length = L_len * first_line = 0 * last_line = 0 * MIMETYPE = ' * E ncoding = Importing Text_buffer = output-zmmjyht010response-output * Output_length = Tables Binary_tab = Lt_bin * EXCEPTIO NS * FAILED = 1 * OTHERS = 2. If SY-SUBRC <> 0. * MESSAGE ID sy-msgid TYPE sy-msgty number Sy-msgno * with Sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. endif. Because it was created based on Pi, at this time the webservice is not registered, Tc:soamanager into single serviceadministration, search for the webservice:zmmjyht010 just created, and apply Selection Click on the Configurations tab to create the service: Remember to tick the User Id/password click on the Show WSDL option and set the WSDL Format to standard, then click Display Sele Ctedbinding ' s WSDL url, on the right side will get the URL of the WSDL in SICF, find the service Zmmjyht010, in the login data, the process data changed to "standard",This is to skip the security policy of the WSDL.

Pi-based WebService publishing instance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.