I’m trying to set up my first Backbone Model that implements RESTful WCF services. Here is what I have so far: My router creates the User Model and I simply want to perform a fetch(). I created a dummy webservice just to try and get it going before I right my actual WS code.
EDIT: I believe this is a problem with my web.config, not sure what I need
MY ROUTER:
define([
'backbone',
'dashboard',
'models/UserModel'
],
function(Backbone, Dashboard, UserModel) {
var homeRouter = Backbone.Router.extend({
initialize : function() {
Backbone.history.start();
},
routes : {
'' : 'home',
'docs': 'docs'
},
'home' : function() {
var user = new UserModel({userId: 'cjestes'});
user.fetch();
},
'docs' : function() {
//load docs page
}
});
return new homeRouter();
});
My MODEL:
define([
'jquery',
'backbone'
],
function($, Backbone) {
//Docs Metro View
var userModel = Backbone.Model.extend({
userId: " ",
url: "services/User.svc/GetUserInformation",
initialize: function () {
this.userId = this.get("id");
}
});
// Return the Docs Model
return userModel;
});
MY SVC:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Activation;
using System.Web.Hosting;
using System.Collections.Specialized;
namespace Mri.Dashboard.services
{
public class User : IUser
{
public string GetUserInformation()
{
return "hello";
}
}
}
MY INTERFACE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
namespace Mri.Dashboard.services
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IUser" in both code and config file together.
[ServiceContract]
public interface IUser
{
[OperationContract]
string GetUserInformation();
}
}
For anyone who stumbles upon this I ended up using a .svc/config – less WCF implmentation. I started with this template which lays out everything you need to do it get REST WCF up and running.
http://visualstudiogallery.msdn.microsoft.com/fbc7e5c1-a0d2-41bd-9d7b-e54c845394cd
I was able to use this template in conjunction with the backbone model’s built in sync, it is very easy to do and use.