Skip to Content

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

/wp-content/uploads/2014/05/clipboard1_456810.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.

/wp-content/uploads/2014/05/clipboard2_456811.png

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

/wp-content/uploads/2014/05/clipboard3_456860.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”.

/wp-content/uploads/2014/05/clipboard4_456861.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.

/wp-content/uploads/2014/05/clipboard5_456862.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.

/wp-content/uploads/2014/05/clipboard6_456863.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:

/wp-content/uploads/2014/05/clipboard7_456864.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”.

/wp-content/uploads/2014/05/clipboard8_456865.png

Maintain user and password:

/wp-content/uploads/2014/05/clipboard9_456866.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.

/wp-content/uploads/2014/05/clipboard10_456867.png

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

/wp-content/uploads/2014/05/clipboard11_456868.png

/wp-content/uploads/2014/05/clipboard12_456869.png

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply