1

I initially started off with an MVC application which contained my JQuery Mobile site and my ServiceStack rest services. My gets and posts were done via AJAX and all is working fine.

I now moved my servicestack rest services to an ASP.NET application and now I am having cross domain issues.

I thought about using JSONP but that will sort out the "gets" but I read I cannot make "post" requests (not too familiar to JSONP at the moment).

I want to know what my options are? Should I

1) just make the AJAX calls back to my MVC controllers and then from there make calls to my new REST services (in the ASP.net app with ServiceStack)

2) Find a way of making cross domain calls (from the browser) if at all possible.

and if I go with 1) is there a performance hit as I am now going to the MVC app and then making a call to the ASP.NET service stack rest services.

JD.
  • 15,171
  • 21
  • 86
  • 159

2 Answers2

1

My vote would be for option 1, especially if the applications are going to be hosted off of the same network / domain.

That said if you were interested in going the cross domain route then that is also an option. In terms of making cross domain gets via jsonp this is the article that helped me greatly get up and running in regards to MVC: http://blogorama.nerdworks.in/entry-EnablingJSONPcallsonASPNETMVC.aspx

Cross domain POSTS are a little annoying as you need to perform a GET request and handle the serialization of any "GET" parameters manually.

Jesse
  • 8,223
  • 6
  • 49
  • 81
1

As you know this isn't an issue when you host ServiceStack and MVC together which you can easily setup with the ServiceStack.Host.Mvc NuGet pacakge as seen in the SocialBootstrapApi demo.

Using a Reverse Proxy

I don't like Option 1) where you proxy all HTTP Requests to ServiceStack via MVC because of the additional code boilerplate and overhead.

If you were to use a proxy it's less overhead, code and cleaner to just configure it below a native/top-level reverse proxy server and route all paths beginning with /api to an internal ServiceStack url with everything else going to your MVC Host. If using IIS you can enable this with IIS Rewrite and Application Request Routing. This is also fairly trivial to setup with Nginx and Apache

Enable Cross-Domain Requests

You can make Cross Domain request by using JSONP or enabling CORS, here's how you can do that in ServiceStack:

servicestack REST API and CORS

Community
  • 1
  • 1
mythz
  • 141,670
  • 29
  • 246
  • 390
  • Thanks, learning new things every minute :). I put in the globalheaders in Apphost.cs and had to put OPTIONS on my RestService attribute and it all works (without changing any of my javascript/mvc code :)). – JD. Jun 12 '12 at 08:43
  • Also, if I have crossdomain.xml file, does it not do the same as what CORS does? – JD. Jun 12 '12 at 08:51
  • crossdomain.xml does the same thing but just works with Flash + Silverlight – mythz Jun 12 '12 at 15:13