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

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.

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

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

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

Click new button:

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

(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.

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

click Confirm Selection to continue.

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

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

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

(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.

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

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.

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

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

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

Search by object name = PROD_WS:

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

Select search result and click Create Service button:

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

Specify Service name and Binding name:

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

Select SSL as Transport Level Security

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

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.

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

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

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

write down the WSDL link:

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

Create the service consumer proxy in ABAP backend

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

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

Choose Service Consumer and click continue:

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

Specify a prefix:

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

Lots of proxy objects for runtime usage will be created:

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

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.

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

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

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

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.

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

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

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

(3) Specify Logical Port name:

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

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

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

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

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

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.

DATA: lo     TYPE REF TO zzco_prod_ws,           input  TYPE zzcrmost__pro001prodadvsea01,
output TYPE zzcrmost__pro001prodadvsea00.

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 zzcrmost__prod_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:

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

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

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

And the result for read operation consumption:

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

要获取更多Jerry的原创文章,请关注公众号"汪子熙":
如何在SAP CRM WebClient UI里创建web service并使用ABAP消费

上一篇:P5655 基础数论函数练习题


下一篇:Codeforces923E