0

This is my first question and I'm quite new to sap development, so I hope I can make this clear enough.

I'm trying to make a call to RFC from an Android app. I created the function module on my company's SAP system and then exposed it as SOAP web service. Then I wrote a sapui5 webapp and then I made it into a cordova project to deploy it on an android device.

To call the SOAP service I use this javascript code in my MainView.controller.js:

$.ajax({
        HTTPHeaders: {
          "Access-Control-Allow-Origin" : "*",
          vary : origin
        },   
        url : "<soap address>", 
        type : "POST", 
        data : request,
        processData : false,
        crossDomain : true,
        cache : false,
        dataType : "text", //xml
        contentType : "text/xml; charset=\"utf-8\"",
        headers : {"Access-Control-Allow-Origin" : "*",
                   "Access-Control-Allow-Methods" : "GET,POST,OPTIONS, PUT, DELETE"},
        externalRequestName : 'ZTestRfc',
        SOAPaction : "urn:sap-com:document:sap:soap:functions:mc-style:zrfc_service:ZTestRfcRequest", 
        success : function(data, textStatus, jqXHR) {
               response = data;
               console.log('success');
               console.log(response);              
        },
        error: function(xhr, status)
        {
               console.log("ERROR");
               console.log(xhr);     
        },
        complete : function(xhr,status) {
               //things
        }
 })

When I run it as a webapp in Chrome, disabling web security, the ajax call works fine, but when I try to run it on the Android device it gives me this error: jquery-dbg.js:10210 POST http:::ERR_NAME_NOT_RESOLVED

I think the problem is related to CORS, since when I try to run the webapp without disabling chrome web security it does tell me that Access to XMLHttpRequest at from origin has been blocked by CORS policy, but so far I haven't found a way to fix it.

I have this in the head tag of my index.html:

<meta http-equiv="Content-Security-Policy" content="default-src *; script-src * 'unsafe-inline'; style-src * 'unsafe-inline'; media-src *; img-src * data:">

And this is my config.xml file (some lines are redundant, I know):

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.innorg.provarfcajax" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>BarcodeScannerPrototype</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="<sap system domain>"/>
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
        <access origin="*" subdomains="true"/>
        <access origin="<sap system domain>/" subdomains="true"/>
        <allow-navigation href="*" />
        <allow-navigation href="<sap system domain>/" />
        <allow-navigation href="<soap url>" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
</widget>

I have the cordova whitelist plugin installed and this line in my android.manifest.xml

 <uses-permission android:name="android.permission.INTERNET" />

Does anyone have any idea on how to make the RFC call work on Android? I know there might be an easier way to call an SAP remote function from Android but I'm new to SAP, to SAPUI5 and to Android development so I basically put together what I found online and ended up with this. I have to use RFC to connect with the SAP system because the system I am working on is super old and doesn't have the NetWeaver Gateway on it. If you know of easier way please tell me and provide an example if you can.

Please tell me if you need any extra information, I will try to provide it.

EDIT: maybe this was already obvious, but my SOAP url is of the kind "http://system domain:8000/service address"

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48

1 Answers1

0

So apparently part of the problem was that the url i used to call the service: while I had updated the hosts file on my laptop to have it point to the right IP address, I hadn't done anything of the sort on the Android device I was trying to deploy the app to, so that explains the ERR_NAME_NOT_RESOLVED error. Putting the IP directly in the URL in place of the system domain fixed it and the Android app runs perfectly fine.

I however haven't found a way around the CORS issue for the web version of the app.