如何处理消费SAP ABAP Web Service时遇到的Unauthorized错误

简介: 如何处理消费SAP ABAP Web Service时遇到的Unauthorized错误

Previously I have written two documents about how to create document template with Word or Adobe PDF format which support web service created by Web service tool available in CRM Web client UI:


(1) Create Webservice enabled word document in attachment assignment block

(2) Create Webservice enabled Adobe PDF attachment in CRM Application


Besides that you could still use external web service from third party or created from a remote function module via tcode SOAMANAGER in ABAP system.


However when you paste the URL of your WSDL as below and press enter key, you meet with the error message “Unauthorized”.


image.png


Before we start to trouble shooting, we’d better quickly go through this document how to create and consume web service in ABAP system to have a basic idea about web service creation and consumption in ABAP system.


Why we will see this Unauthorized error message

The position of this error message could easily be found via the tip described in my blog How to quickly locate the source code where raises a given message in webclient UI:


The WSDL URL we input is used to initialize one instance of cl_http_client and then cl_http_client~send and cl_http_client~receive are called to get the content of this WSDL.


image.png


Then we get expected 401 Unauthorized error, since we didn’t specify any credentials in this generic code.


image.png


go to tcode SICF and find the ICF node /default_host/sap/bc/ ( which is the parent node of the ICF service generated for our web service), the logon procedure for it is set as “Standard”.


image.png


According to SAP help, Standard logon procedure means the framework will do authentication check based on the following orders until one avalid credential found. In our case, none of the seven attempts succeed, so finally we see 401 Unauthorized error.


image.png


How to resolve the error

According to SAP help, after I add the following code to enable HTTP Basic Authentication, the error is gone.


image.png


Of course this could not be used in productive code, we need to find a more generic solution.

Go outer callstack of 401 error, I find there is another way to initialize http client instance by RFC destination instead ( line 49 ).

Doing a where used list on class attribute mv_destination and soon I found there is a BAdI definition which could allow us to specify a HTTP destination for the external web service being used:


image.png


So the solution would be:


(1) Create a HTTP destination in tcode SM59

Maintain “Target Host”, “Service No.”( that is port number ) and paste the left part of WSDL URL to “Path Prefix”.


image.png


Maintain user and password:


image.png


(2) Create a BAdI implementation on BAdI definition CRM_OI_WEBSERVICE_BADI


Implement the method GET_SERVICE_DESTINATION. fill the changing parameter cv_destination. You could do filtering based on the importing WSDL URL and Operation, in this example I just hard code the name of RFC destination created in step one.


image.png


Now this destination will be used to create http client instance and the 401 error message is then resolved.


image.png


相关文章
|
1月前
|
开发者 供应链 BI
SAP ABAP CALL SUBSCREEN 代码解析
SAP ABAP CALL SUBSCREEN 代码解析
52 0
|
1月前
|
SQL Android开发
创建 SAP ABAP CDS View 保存失败 - Dependencies DDL source - View Entity not written
创建 SAP ABAP CDS View 保存失败 - Dependencies DDL source - View Entity not written
9 0
创建 SAP ABAP CDS View 保存失败 - Dependencies DDL source - View Entity not written
|
1月前
|
SQL 数据库 索引
关于 SAP ABAP REPOSRC 数据库表在 HANA 中的 DDL Definition
关于 SAP ABAP REPOSRC 数据库表在 HANA 中的 DDL Definition
20 1
关于 SAP ABAP REPOSRC 数据库表在 HANA 中的 DDL Definition
|
2月前
|
存储 开发框架 JSON
在 Python 中,如何处理 Web 请求和响应?
【2月更文挑战第26天】【2月更文挑战第90篇】在 Python 中,如何处理 Web 请求和响应?
|
1月前
|
存储
使用 ABAP 代码打印出 SAP CRM 系统里所有维护了 Sales Area 的 business partner id
使用 ABAP 代码打印出 SAP CRM 系统里所有维护了 Sales Area 的 business partner id
21 0
|
1天前
|
SQL Oracle 关系型数据库
SAP* DDIC密码丢失如何处理
SAP* DDIC密码丢失如何处理
|
1月前
关于 SAP ABAP OData 服务如何实现 Deep Insert 场景 - SAP 应用的标准行为试读版
关于 SAP ABAP OData 服务如何实现 Deep Insert 场景 - SAP 应用的标准行为试读版
16 1
|
1月前
|
人工智能
Suno AI 生成 SAP ABAP 顾问之歌
Suno AI 生成 SAP ABAP 顾问之歌
22 1
|
1月前
|
存储 安全 数据库
SAP ABAP 中数据类型 xstring 的使用介绍
SAP ABAP 中数据类型 xstring 的使用介绍
29 0
|
1月前
什么是 SAP ABAP 里的 Subscreen
什么是 SAP ABAP 里的 Subscreen
16 1
什么是 SAP ABAP 里的 Subscreen

热门文章

最新文章