2015-03-02 116 views
1

有人可以告诉我如何配置WCF端点以便从JQuery Ajax调用中调用以下RESTful Web服务。我的例子服务代码:如何为客户端jQuery调用配置WCF RESTful端点

namespace MyService 
    { 
     [ServiceContract] 
     [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
     public class Service 
     { 
      [OperationContract] 
      [WebGet(UriTemplate = "/GetDepartment")] 
      public Department GetDepartment() 
      { 
       ... code 
      }; 
      return data; 
     } 
    } 

jQuery代码:

  var jData = {}; 

     $.ajax({ 
      cache: false, 
      type: "POST", 
      async: true, 
      url: "MyService/GetDepartment", 
      data: JSON.stringify(jData), 
      contentType: "application/json", 
      dataType: "json", 
      success: function (jsondata) { 
      ... code 
     }, 
     error: function (xhr) { 
      alert(xhr.responseText); 
      } 
     }); 

回答

0

尝试以下各项

function SaveBook() { 

     var bookData = {}; 

     $.ajax({ 
      type: “POST”, 
      url: “MyService/GetDepartment″, 
      data: JSON.stringify(bookData), 
      contentType: “application/json; charset=utf-8″, 
      dataType: “json”, 
      processData: true, 
      success: function (data, status, jqXHR) { 
       alert(“success…” + data); 
      }, 
      error: function (xhr) { 
       alert(xhr.responseText); 
      } 
     }); 
    } 
+0

谢谢您的答复。我需要的是Web.config端点配置设置。示例: – 2015-03-02 12:06:57

+0

2015-03-02 12:08:23

+0

太棒了!你的问题现在解决了吗? – 2015-03-02 12:30:10