如何从我的WCF服务中提供元数据以供Breeze使用

时间:2013-06-07 02:03:47

标签: wcf breeze single-page-application

我正在尝试调整现有的WebApi / MVC4应用程序以使用Breeze查找。

目前我通过

检索我的DTO
    [HttpGet]
    public IQueryable<ThingDto> GetThings()
    {

        var channelFactory = ThingServiceConfiguration.CreateChannelFactory();
        _serviceFactory = () => new WcfProxy<IThingService>(channelFactory.CreateChannel());

        var client = _serviceFactory();

        IQueryable<ThingDto> result = client.Execute(p => p.GetThings()).OrderBy(x => x.Name).AsQueryable();

        return result;
    }

我不确定如何实现此方法Metadata()

 public string Metadata()
 {
      //normally something like this if using a EF DataContext
      // return _someContextProvider.Context.Things;

 }

我如何设置WCF配置

public class ThingServiceConfiguration
{
    const string AppSettingKey = "ThingServiceUrl";

    public static ChannelFactory<IThingService> CreateChannelFactory()
    {
       // var serviceUrl = ConfigurationManager.AppSettings[AppSettingKey];
        var serviceUrl = "http://localhost:86/ThingService.svc";
        var binding = new BasicHttpBinding(BasicHttpSecurityMode.None)
        {
            MaxReceivedMessageSize = 200000000,
            SendTimeout = TimeSpan.FromMinutes(2),
            ReceiveTimeout = TimeSpan.FromMinutes(2)
        };
        var address = new EndpointAddress(serviceUrl);
        return new ChannelFactory<IThingService>(binding, address);
    }
}

这个元数据是否可以通过WCF调用Metadata()属性提供(通过BasicHttpBinding提供参数?

非常感谢!

1 个答案:

答案 0 :(得分:0)

只需返回json格式的元数据,即可返回Breeze'native'元数据。像这样:

[HttpGet]
public String Metadata() {
  var folder = Path.Combine(HttpRuntime.AppDomainAppPath, "App_Data");
  // metadata.json is the name of a file containing your metadata - pick any file name you like.
  var fileName = Path.Combine(folder, "metadata.json");
  var jsonMetadata = File.ReadAllText(fileName);
  return jsonMetadata;
}

这里描述了元数据文件的语法:Breeze metadata format