1
我试图设置我的第一个实现RESTful WCF服务的骨干模型。这是我到目前为止:我的路由器创建用户模型,我只是想执行一个fetch()。我创建了一个虚拟web服务,只是为了在我正确使用WS代码之前尝试去实现它。400(错误请求)错误:从骨干模型的获取基础架构调用WCF .net服务
编辑:我相信这是我的web.config一个问题,不知道我需要什么
我的路由器:
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();
});
我的模型:
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();
}
}
显示您没有使用[WebGet]属性注释您的服务合同!为了使用REST wcf,您需要通过UriTemplate =“GetUserInformation”将OperationContract映射到URI:[WebInvoke(UriTemplate =“GetUserInformation”)] – CjCoax 2012-02-09 05:32:12