Geeks With Blogs

News Cloud development with Azure, Visual Studio and SharePoint Online!
Thorvald Bøe
I had the following scenario:
1 SharePoint onPremise site installed on IIS port 80
1 Dynamics NAV site with some web services to be utilized on the SharePoint site

My task was to create some web parts to display project information coming through the NAV web services. As I have used the content editor web part with jQuery pattern very successfully in the past, I saw no reasons why it shouldnt work this time. It did, but I ran into a few hickups.

First, I needed to consume the web services from jQuery. Running into problems with both SOAP details and authentication, I decided to write a MVC REST api to work as a proxy between the web services and the web parts. The REST api consumed the web services with no problems, and also solved the authentication problems. Since I was planning to deploy this on the SharePoint server, I would also avoid any cross domain issues with calling the REST api from jQuery, or so I thought. But I was wrong!

As it turns out, cross domain issues occur even if you are accessing information on the same server but another port. I also tried adding an Access-Control-Allow-Origin header to allow different origins, but that did not help. I was running out of time and had no time to investigate it further.

Finally, I came up with a solution that was working. I thought of installing the REST proxy in a subfolder on the SharePoint web site. What I did, was almost that, but a little cleaner:
1.I added a new virtual directory directly below the top level on the SharePoint web server, calling it CustomWebServices
2.I then pointed the virtual directory to the physical location of the web site I had already set up on a different port
3.Finally, I right clicked the virtual directory and chose "Convert to application"

Apparently the last step makes SharePoint not imposing its own web.config on the application, and it worked correctly. 

I was now able to make ajax calls in jQuery from within a CEWP in SharePoint, calling methods of the API without any cross domain issues. A nice and easy way to display Dynamics NAV data inside SharePoint!
Posted on Tuesday, February 18, 2014 12:57 PM jquery , sharepoint , Dynamics NAV , Cross domain | Back to top

Comments on this post: Solving cross domain issues

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Thorvald Bøe | Powered by: