如何处理消费SAP ABAP Web Service时遇到的Unauthorized错误-阿里云开发者社区

开发者社区> jerrywangsap> 正文

如何处理消费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


版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
如何处理Angular应用的错误消息: No pipe found with name async
如何处理Angular应用的错误消息: No pipe found with name async
7 0
RocketMQ消费失败消息深入分析(consumer,broker的具体处理逻辑)
消息队列是分布式系统中重要的组件,主要解决应用耦合,异步消息,流量削锋等问题
2089 0
Web系统下Office文档的处理
在web环境中,我们经常遇到需要对Office文档进行各种各样的处理,如:格式转化、统计、修改等各种操作,如果使用Office的客户端对象模型直接处理,一般会遇到:效率低;服务器资源负载大等一系列问题,毕竟Office对象实现时主要针对的是客户端的使用而设计的,对于批量和大负载的处理自然效率欠佳。
773 0
Web系统下Office文档的处理 之OpenXml应用分类资料
本文对常见的处理参考和工具提供一个简要的参考。 对于实际的解决方案参考如下地址(有很多的分类知识) http://blogs.msdn.com/b/ericwhite/archive/2008/10/20/eric-white-s-blog-s-table-of-contents.
964 0
ML之SVM:利用SVM算法对手写数字图片识别数据集(PCA降维处理)进行预测并评估模型(两种算法)性能
ML之SVM:利用SVM算法对手写数字图片识别数据集(PCA降维处理)进行预测并评估模型(两种算法)性能
24 0
如何处理使用 SAP UI5 消费真实的 OData 服务时遇到的跨域问题
如何处理使用 SAP UI5 消费真实的 OData 服务时遇到的跨域问题
11 0
+关注
2628
文章
0
问答
来源圈子
更多
+ 订阅
文章排行榜
最热
最新
相关电子书
更多
《2021云上架构与运维峰会演讲合集》
立即下载
《零基础CSS入门教程》
立即下载
《零基础HTML入门教程》
立即下载