JSONP(JSON with Padding)可以看成是JSON的一种“使用模式”,用以解决“跨域访问”的问题,这篇简单的文章给出一个简单的例子用于模拟如何通过jQuery以JSONP的访问调用一个WCF REST服务。[源代码从这里下载]

在这个例子中,我们将定义一个用于返回所有员工信息的服务,下面是用于表示员工信息的Employee的类型和契约接口。契约接口IEmployees的GetAll操作用以返回所有员工列表,我们指定了Uri模板并将回复消息格式设置为JSON。

using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Web;
namespace Artech.WcfServices.Service.Interface
   5: {
   6:     [ServiceContract]
interface IEmployees
   8:     {
,ResponseFormat =WebMessageFormat.Json)]      
  10:         IEnumerable<Employee> GetAll();
  11:     }
class Employee
  13:     {
string Id { get; set; }
string Name { get; set; }
string Department { get; set; }
string Grade { get; set; }
  18:     }
  19: }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-25
  • 2021-08-26
  • 2021-06-26
  • 2021-10-16
  • 2022-12-23
猜你喜欢
  • 2022-01-22
  • 2021-06-21
  • 2022-02-19
  • 2022-12-23
  • 2021-05-24
相关资源
相似解决方案