Options

Nav 2018 Web service

suraj92291suraj92291 Member Posts: 49
Hello experts,

im trying to access nav 2018 codeunit web service from android/php (which env is on different server) but keep getting error

" Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 401."

any help would be greatly apprecited

sam
“Any fool can know. The point is to understand.”
― Albert Einstein

Answers

  • Options
    RemkoDRemkoD Member Posts: 100
    Just to rule things out. Have you've tried to access the NAV webservice on the android/php machine through a web browser or something? Do you get the WSDL page?

    If that is working I would expect that you have to fix the issue on the request side. The code that is making the request package that is send to the NAV app server.
  • Options
    suraj92291suraj92291 Member Posts: 49
    Im able to call it from PHP/c# but its giving same error for android ionic framework..

    sam
    “Any fool can know. The point is to understand.”
    ― Albert Einstein
  • Options
    suraj92291suraj92291 Member Posts: 49
    Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience. For more help http://xhr.spec.whatwg.org/
    soapjs.php:41:12
    Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://111.111.11.111:11111/NAV2018/WS/SystemService. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
    “Any fool can know. The point is to understand.”
    ― Albert Einstein
  • Options
    RemkoDRemkoD Member Posts: 100
    edited 2018-05-14
    The Same Origin Policy disallows reading the remote resource
    To me this looks like that the request is blocked from the site you're developing that launches the request to the NAV webserver. I think your webserver is configured to only access sources from localhost and not from remote servers (your Dynamics NAV server).

    More information about Access-Control-Allow-Origin. You can configure the webserver to allow resources from another origin/server. You can also test if this is the issue by including this into the header from your PHP script.

    Anyway I doubt this is a Dynamics NAV Webservice issue. You might as well try other forums :)
  • Options
    endjinnendjinn Member Posts: 11
    edited 2018-12-04
    > @suraj92291 said:
    > Hello experts,
    >
    > im trying to access nav 2018 codeunit web service from android/php (which env is on different server) but keep getting error
    >
    > " Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 401."
    >
    > any help would be greatly apprecited
    >
    > sam

    Hi Sam, I had the exact same issue with Ionic/Javascript AJAX soap call. It looks like a direct connection to the exposed codeunit isn't supported as you can't set the CORs header/method in the NST config. I went back to the proxy method, made a C# ASMX web service that wraps the NAV gateway function. I let the ASMX handle the authentication.

    Also in IIS for the proxy I set the CORs properties (Origin/Method etc.). This isn't a great solution as I'd ideally wanted to rule out using a proxy due to non on premise customers (D365 BC) but what can you do?

    Anyway give me a shout if you want the code snippets, happy to share the Ajax / ASMX if it helps.

    Cheers Andy, Dionix
  • Options
    abouziopoulosabouziopoulos Member Posts: 1
    Hi Andy,

    Can you share your Ajax / ASMX solution ?
Sign In or Register to comment.