ITPub博客

首页 > 应用开发 > IT综合 > 如何在SAP CRM WebClient UI里创建web service并使用ABAP消费

如何在SAP CRM WebClient UI里创建web service并使用ABAP消费

原创 IT综合 作者:i042416 时间:2020-08-19 11:28:10 0 删除 编辑

In this blog I will create a web service which is exposed via Genil model PROD in CRM web client UI and consume it via a simple ABAP program.

Create web service in CRM Webclient UI

(1) log on CRM Web UI with business role SERVICEPRO, work center Service Operation, Create a new Web service: Choose Material as Business Object, choose Product/Individual Product as Component, Product as Root object. Mark check box Read, Create and Change.



Click the new button to also create a Web service operation which is implemented via the query object of Genil model



Click new button:



(2) in step 2 of the creation wizard, simply click select all to ensure all attributes in Genil model PROD are involved in the web service.



click Confirm Selection to continue.



(3) in step 3, it is allowed to specify certain fields as read only.



(4) In final step of wizard, we can specify the security profile of created web service. The differences of the two can be found in the chapter when we talk about how to consume the web service. In this blog I choose BASIC as security profile.



Click Activate button and then click Productive button in toolbar. Now we have finished the creation and the web service PROD_WS is ready to be consumed.



Create new binding for Service Definition PROD_WS use tcode SOAMANAGER, click Web Service Configuration.



Search by object name = PROD_WS:



Select search result and click Create Service button:



Specify Service name and Binding name:



Select SSL as Transport Level Security



If you select SECURE as security profile in web service creation step, the Authentication Level will be Strong instead of Basic, and the checkbox “User ID/Password” will be disabled, which means in that case, only X.509 SSL Client Certificate or Single Sign On are allowed.

In this blog, since both the creation of web service and service consumption are done in AG3, I mark “Make Local Call” as Local System Call.



Click Finish button, click the icon “Open Binding WSDL Generation”,



write down the WSDL link:



Create the service consumer proxy in ABAP backend

(1) tcode SE80, choose tab “Enterprise Services Browser”, right click on Objects, choose “Create new Object”,



Choose Service Consumer and click continue:



Specify a prefix:



Lots of proxy objects for runtime usage will be created:



Finally the ABAP consumer proxy class ZZCO_PROD_WS has been generated, which would be used in the ABAP program to consume the web service.



Now the consumer proxy class is ready for use. We can find all its available methods and signature in class builder.



In  part 2 of this blog, we will discuss how to use this proxy class to consume web service in ABAP program.

In previous  blog we have finished the creation for web service PROD_WS, and ABAP consumer proxy class ZZCO_PROD_WS. Before it can be used in ABAP program to consume the web service we created, a logical port is needed.

Create a new Logical Port in SOAMANAGER

(1) Go back to SOAMANAGER and search PROD_WS again, this time the ABAP consumer proxy ZZCO_PROD_WS is also visible in search result list.



(2) Click consumer proxy class and click button Create->WSDL Based Configuration:



(3) Specify Logical Port name:



Specify the WSDL link of new binding for service definition created in previous step. Specify a valid user and password for WSDL access.



Click finish button to finish logical port creation. Click Ping button and ensure it works successfully.



Consume the web service in ABAP program Use the following source code to consume the query and read service operation. Pass the logical port name LP__TEST1 in constructor of consumer class. The data type and method signature could be easily found in class builder for consumer proxy class ZZCO_PROD_WS.

```ABAP DATA: lo TYPE REF TO zzco_prod_ws, input TYPE zzcrmost pro001prodadvsea01, output TYPE zzcrmostpro001prodadvsea00.

CREATE OBJECT lo EXPORTING logical_port_name = 'LP_TEST1'.

input-input-searchforproducts-created_by-sign = 'I'. input-input-searchforproducts-created_by-option = 'EQ'. input-input-searchforproducts-created_by-low = 'WANGJER'.

TRY. lo->crmost__pro001prodadvsea001d( EXPORTING input = input IMPORTING output = output ). CATCH cx_root INTO DATA(lv_text). DATA(ls) = lv_text->get_text( ). WRITE:/ ls. ENDTRY.

DATA: ls_read_input TYPE zzcrmost prod_ws_read, ls_read_result TYPE zzcrmostprod_ws_read_respo.

TRY. ls_read_input-input-prod_ws-product_id = 'ARNO_TEST004'. lo->crmost__prod_ws_read( EXPORTING input = ls_read_input IMPORTING output = ls_read_result ). CATCH cx_root INTO lv_text. ls = lv_text->get_text( ). WRITE:/ ls. ENDTRY. ``` program execution result: 100 results found with CREATED_BY = WANGJER:



The result is exactly the same as when we manually run the advanced search in GENIL_BOL_BROWSER:



And the result for read operation consumption:



要获取更多Jerry的原创文章,请关注公众号"汪子熙":


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24475491/viewspace-2712839/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
SAP成都研究院开发专家,SAP社区导师,SAP中国技术大使。

注册时间:2018-01-20

  • 博文量
    1914
  • 访问量
    882470