How to resolve Unauthorized error message when defining external web service for document template
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:
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”.
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.
Then we get expected 401 Unauthorized error, since we didn’t specify any credentials in this generic code.
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”.
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.
How to resolve the error
According to SAP help, after I add the following code to enable HTTP Basic Authentication, the error is gone.
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:
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”.
Maintain user and password:
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.
Now this destination will be used to create http client instance and the 401 error message is then resolved.
Hello Jerry,
This workaround worked for us for several years.
However, since our upgrade from Ehp4 SP4 naar Ehp4 SP9,
the call to IF_CRM_OI_WS_DT~GET_WSDL_CONTENT of class CL_CRM_OI_WS_EXT_DT returns a status 500 with reason 'WSDL could not be generated',
when the cl_http_client instance was instantiated from the create_by_destination call.
Are you aware of any reason why this workaround would not work anymore?
Thanks,
Piet
Hello Piet,
Unfortunately not, I have not been working on this topic for 4 years. I suggest you raise an incident to SAP, my colleagues in other site will work on it.
Best regards,
Jerry
Hi Jerry,
As an update and to whom it may concern: note 2694522 solved our problem.
Best Regards,
Piet