【转自http://blog.csdn.net/yin_chuan_lang/article/details/6706816】

最近的项目中,接口较多,而Webservice技术是主要实现方式之一。下面以项目中的一个具体实例来体验一下基于PI的Webservice发布。 业务场景 SAP系统实时接收一个外围接口系统(基于Web的电子商务平台)回传的数据。 技术分析 由于同步要求较高,数据量偏小,采用Webservice实现较为合理。 实例演示 创建好自建表,用于接收回传的数据: TC: SPROXY根据集成组在PI配置的服务名创建Service Interface 在实现类中,根据传入的XML字符串,解析后更新到自建表: data: ls_field_data like zmmjyh_cdif, lt_field_data like table of ls_field_data, ls_zmmjyh_ht_0007 like zmmjyh_ht_0007, lt_zmmjyh_ht_0007 like table of ls_zmmjyh_ht_0007, l_retcode type i, l_fieldname type string, l_float type f. field-symbols: <fs_fieldname> type any, <fs_fieldvalue> type any. "解析XML数据到通用内表 type-pools: ixml. types: begin of t_xml_line , data(256) 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_xmldata 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_document ). * 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_map, node_parent type ref to if_ixml_node, attr type ref to if_ixml_node, name type string, name1 type string, prefix type string, 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 while 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( ). "记录字段名、字段值 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( ). "记录字段名、字段值 p_i_zxml-fieldname = name1 . p_i_zxml-fieldvalue = value . append p_i_zxml . endcase. node = iterator->get_next( ). endwhile. endform. "process_dom "准备数据到数据库更新内表 loop at lt_field_data into 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'. "金额字段中科学计数法的处理 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 = '程序异常,字段名不匹配!'. append it_return. return. endif. "到达一条数据末尾 if ls_field_data-fieldname = 'PREPAYID'. append ls_zmmjyh_ht_0007 to lt_zmmjyh_ht_0007. clear ls_zmmjyh_ht_0007. endif. endloop. "更新到自建表 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 = '回传成功!'. append it_return. else. rollback work. it_return-zresult = '0'. it_return-description = '回传失败,数据库更新异常!'. append it_return. endif. else. it_return-zresult = '0'. it_return-description = '无数据可传输!'. append it_return. endif. 把结果回传给外围系统,先创建好Transformation 然后把返回值封装成XML串: 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(1024) type x, end of ty_bin. data:lt_bin type table of ty_bin."文件二进制内表 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 tables binary_tab = lt_bin . call function 'SCMS_BINARY_TO_STRING' exporting input_length = l_len * FIRST_LINE = 0 * LAST_LINE = 0 * MIMETYPE = ' ' * ENCODING = importing text_buffer = output-zmmjyht010response-output * OUTPUT_LENGTH = tables binary_tab = lt_bin * EXCEPTIONS * 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. 由于是基于PI创建的,此时的Webservice还没有注册,TC:SOAMANAGER 进入single serviceadministration,搜索刚才创建的webservice:Zmmjyht010,并apply selection 点选Configurations标签,创建服务: 记得勾选中 User ID/Password 点击 show wsdl options,并把 WSDL Format 设置为standard,然后点选Display selectedBinding's WSDL URL, 在右边会得到WSDL的URL 在SICF中,找到服务 Zmmjyht010,在登录数据里,把过程数据改为 “标准”,这是为了跳过WSDL的安全策略。

基于PI的Webservice发布实例的更多相关文章

  1. 基于JAX-WS的webService开发实例

    最近因为工作原因接触到webService,所以记录下开发中碰到的问题,方便自己以后复习,顺便发扬一下开源精神.刚刚接触webServie如果有什么错误欢迎大家指正. 本地环境:myEclipse10 ...

  2. python发布及调用基于SOAP的webservice

    现如今面向服务(SOA)的架构设计已经成为主流,把公用的服务打包成一个个webservice供各方调用是一种非常常用的做法,而应用最广泛的则是基于SOAP协议和wsdl的webservice.本文讲解 ...

  3. Java WebService入门实例

    Web Services是由企业发布的完成其特定商务需求的在线应用服务,其他公司或应用软件能够通过Internet来访问并使用这项在线服务. Web Service的关键技术和规则: 1.XML:描述 ...

  4. WebService入门实例教程

    什么是WebService 通过使用WebService,您的应用程序可以向全世界发布信息,或提供某项功能,它是基于Web的服务,通过Web进行发布.查找和使用. WebService脚本平台需支持X ...

  5. 基于.NET的WebService的实现和WCF的实现

    1.新建一个MVC web项目. 2.点击项目,[右键]→[添加]→[新建项] 3.点击[Web]→[Web服务] 4.恭喜,Web Service已经新建成功,里面的方法就可以参考着根据自己的需要进 ...

  6. 主题:Java WebService 简单实例

    链接地址:主题:Java WebService 简单实例    http://www.iteye.com/topic/1135747 前言:朋友们开始以下教程前,请先看第五大点的注意事项,以避免不必要 ...

  7. 【转】构建基于CXF的WebService服务

    构建基于CXF的WebService服务 Apache CXF = Celtix+ XFire,开始叫 Apache CeltiXfire,后来更名为 Apache CXF 了,以下简称为 CXF.C ...

  8. Webservice发布

    此文甚好,转载自:http://blog.163.com/java_player@126/blog/static/127930738200981555021925/ 某些地方笔者已经加以改进. 使用工 ...

  9. Myeclipse8.5上基于JAX-WS开发WebService

    1.JAX-WS介绍 JAX-WS规范是一组XML web services的JAVA API. 2.开发步骤 基于JAX-WS的WebService开发步骤如下: 2.1 新建一个Web Servi ...

随机推荐

  1. VB断点调试

    最近都在敲机房收费系统,这个系统是我们第一次自己在没有源代码的情况下进行的系统. 写程序的时候逻辑非常重要,可是我们还要清楚非常多时候你以为的并非你以为的! 就像在敲机房的时候,我们明明理清了逻辑.并 ...

  2. 企业级分布式存储应用与实战MogileFS、FastDFS

    项目实战9—企业级分布式存储应用与实战MogileFS.FastDFS   目录 实战一:企业级分布式存储应用与实战 mogilefs 实现 原理 1.环境准备 2.下载安装,每个机器都一样 3.数据 ...

  3. EularProject 39:给周长推断构成直角三角形个数

    华电北风吹 天津大学认知计算与应用重点实验室 完毕日期:2015/7/30 Integer right triangles Problem 39 If p is the perimeter of a ...

  4. Python基础之模块2

    如何导入多个模块? import re #单行导入多个模块 '''多行导入多个模块''' import re import sys import os 如何给模块起别名? import my_modu ...

  5. poj 2553 The Bottom of a Graph(强连通、缩点、出入度)

    题意:给出一个有向图G,寻找所有的sink点.“sink”的定义为:{v∈V|∀w∈V:(v→w)⇒(w→v)},对于一个点v,所有能到达的所有节点w,都能够回到v,这样的点v称为sink. 分析:由 ...

  6. 安卓TabHost+ViewPager+RadioGroup多功能模板整理

    如今安卓比較流行的布局就是类似新闻client和手机QQ那种的底端可选择,上面的个别页面能够滑动选择. 在測试过程中发现用安卓自带的TabHost去构建.非常难得到自己定义的效果. 因此採用TabHo ...

  7. nginx反向代理带路径访问问题

    nginx的配置为192.168.0.219:80分别映射到upstream组192.168.0.55:8080和192.168.0.206:8080,那如何配置做到访问192.168.0.219:8 ...

  8. ThinkPHP3.1URL分发BUG修正

    请先留意以下PHP脚本 PHP脚本A(http://127.0.0.1:8110/test.php): $url = 'http://127.0.0.1:8110/demo.php'; //curl请 ...

  9. 【Python+selenium Wendriver API】之下拉框定位

    上代码: # coding:utf-8 from selenium import webdriver from selenium.webdriver.common.action_chains impo ...

  10. COM对象模型

    COM对象内存布局,多继承是虚继承吗? 接口之间怎么切换? 1) 是普通的多继承,不是虚继承.因为父类接口只是含有纯虚函数,不含任何数据成员,所以问题不大. 2) QueryInterface可以用来 ...