Test SAP Connections and Versions failing with an "Couldn't find a valid mid server"


Description

During implementation of Software Asset Management while creating create a connection to SAP the connection fails.
When we create the connection and choose the related link "Test SAP Connections and Versions" we get an error "couldn't find a valid mid server".
See the attached screenshot.

Release or Environment

All

Cause

The error in the System Logs for this transaction will look like below:


Error Default-thread-9 72CCEA9FDBA064501DFA2D8913961927 txid=e8f1f69bdb24 SEVERE *** ERROR *** *** Script: SAPImportWorker Exception while executing the api GET_SAP_VERSION Error is Error: SAMSoapHandler: Couldn't find a valid mid server;
07:09:53.149 Error Default-thread-9 72CCEA9FDBA064501DFA2D8913961927 txid=e8f1f69bdb24 SEVERE *** ERROR *** *** Script: SAPImportWorker.getLatestSapVersion : Can not get the lastest SAP version, returned with response : {0}SAMSoapHandler: Couldn't find a valid mid server;
07:09:53.151 Info Default-thread-9 72CCEA9FDBA064501DFA2D8913961927 txid=e8f1f69bdb24 GlideSession message was modified by sanitization. [message=Request failed with response : SAMSoapHandler: Couldn't find a valid mid server][sanitized=Request failed with response : SAMSoapHandler: Couldn't find a valid mid server];


There could be multiple causes for seeing the error:
1] Verify the connection section has all the required attributes.
https://<instance>.service-now.com/nav_to.do?uri=samp_sap_connection.do?sys_id=<sys_id_of_connection_errored>

2] Verify if the SOAP Message attributes are set correctly:
https://<instance_name>.service-now.com/nav_to.do?uri=sys_soap_message.do?sys_id=

3] Ensure the Mid server associated to the WSDL is up and running.
4] Verify if the credentials are set correctly.

5] From the System Logs error message "Can not get the lastest SAP version", the script responsible for the above error is found in the below link:
https://<instance_name>.service-now.com/nav_to.do?uri=sys_script_include.do?sys_id=45746ceb73631300c9b2cb15d4f6a79e

5.1]  In SAMSoapHandler.execute, we call SAMSoapHandler.getMIDServer which calls back-end java Mid selector code. However, from verifying the function definition that tests the mid server connection with the target in the code [selecAnyMidServer(null, target, null)] this seems to expect an IP address as an input.
5.2] The selection of MID server is done by passing the host as configured in the connection wsdl. Seems here we are not able to determine the host and thus the error.

Resolution

1] Current WSDL URL configured may look like below:
http://<hostname>.<domain_name>.prv:8040/sap/bc/srt/wsdl/flv_10002A111AD1/srvc_url/sap/bc/srt/rfc/now/samp/120/now_samp/now_samp?sap-client=120

2]  Please try updating the wsdl in the connection to use IP address like (e.g: 192.10.254.12) instead DNS of name. You could create a new connection if necessary.
Work with your internal Admin team to determine the IP and update the SOAP message wsdl with the respective IP instead of the domain URL.
http://<ip_address>:8040/sap/bc/srt/wsdl/flv_10002A111AD1/srvc_url/sap/bc/srt/rfc/now/samp/120/now_samp/now_samp?sap-client=120


3) If DNS still has to be used, this could be achieved by creating a record in the table - cmdb_ci_dns_name for the URL to map it with the respective IP address. You could follow the below link for the same:
https://docs.servicenow.com/bundle/paris-servicenow-platform/page/product/mid-server/task/t_MapIPAddressToDNSName.html