2012-02-08 31 views
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(); 
    } 
} 
+1

顯示您沒有使用[WebGet]屬性註釋您的服務合同!爲了使用REST wcf,您需要通過UriTemplate =「GetUserInformation」將OperationContract映射到URI:[WebInvoke(UriTemplate =「GetUserInformation」)] – CjCoax 2012-02-09 05:32:12

回答

相關問題