Zippy Tips Working With ServiceStack, Backbone.js, jQuery & Mono-Develop on Mac

Okay, just some random nigglies I’m experiencing and sort of solved, working with ServiceStack, Backbone.js, Mono & Mono-Develop on Mac.

MonoDevelop & XSP dev web server

Not sure who else is experiencing this issue, but my MonoDevelop and XSP dev web server gets confused sometimes, after a while. I launch two projects when I click play in my project, a web service based on ServiceStack and a ASP .NET project based on Backbone.js. For some weird reason after N number of times relaunching these 2 web projects from MonoDevelop – XSP and MonoDevelop loses track of the web service’s XSP process. The problem then is that I’m unable to re-launch the web service project with a new version.

So… in terminal do “lsof -i -P | grep [port-number-of-xsp-project-website]“. This will give you the XSP process ID. Then, again in terminal, do a “sudo kill [pid]“, to kill the ghost XSP process.

Great now you can continue launching XSP from MonoDevelop.

Cross Domain/Site Scripts with jQuery & Backbone.js

Riiight, so, I was doing the whole preflight thing with jQuery $.ajax. In Firebug I could see the OPTIONS request being made and the server returning the a 200 OK, with the following headers: Access-Control-Allow-Origin and Access-Control-Allow-Methods. BUT, $.ajax never made the actual request to PUT or POST the data to my ServiceStack web service. Well, it turns out another header is required to be returned by the web server’s response to the OPTIONS request: Access-Control-Allow-Headers, with a value of Content-Type.

So when using ServiceStack make sure you set your GlobalResponseHeaders in your AppHosts Configure(…) method:

public override void Configure(Container container)
SetConfig(new EndpointHostConfig
GlobalResponseHeaders =
{ "Access-Control-Allow-Origin", "*" }, // You probably want to restrict this to a specific origin
{ "Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS" },
{ "Access-Control-Allow-Headers", "Content-Type" }

Saving Models In Backbone.js

When you want to update a model, make sure you call{ anUpdatedProperty: newValue, anotherUpdatedProperty: newValue }), instead of just, otherwise boggerrol will happen.

When your Backbone.js app talks to a web service that serializes data into a CamelCase format, like C#’s properties, then Backbone’s collection.get(…) won’t work for you, because your model’s id property‘s name will be “Id” and not “id”. To get around this add the idAttribute to your Backbone.js Model, to reroute id to your chosen property on the model object:

var theModel = Backbone.Model.extend(
idAttribute: "Id"

Cool. That’s it for now. Catch you on the flip side!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s