创建数据源 WCF 数据服务

发布于 2024-11-28 06:51:11 字数 1078 浏览 1 评论 0原文

我似乎无法弄清楚在调用 CreateDataSource 时获取在 silverlight 客户端上填充的自定义标头。我有以下代码:

protected override CaseEntitiesContext CreateDataSource()
{
  return new CaseEntitiesContext(CaseGuid, ConnectionString, Provider)
  {
    DefaultContainerName = "CaseEntitiesContext"
  };
}

我从 web.config 获取 ConnectionString 和 Provider,但需要从 RequestHeader 获取 CaseGuid。

如果我在构造函数中或内联添加以下代码,则代码将在 CreateDataSource 之后执行。

      ProcessingPipeline.ProcessingRequest += (o, args) =>
    {
      CaseGuid = new Guid(args.OperationContext.RequestHeaders["caseguid"]);
      Debug.WriteLine("request case guid:" + args.OperationContext.RequestHeaders["caseguid"]);
      Debug.WriteLine("CaseRequest Processing HTTP {0} request for URI {1} Case Guid {2}",
          args.OperationContext.RequestMethod,
          args.OperationContext.AbsoluteRequestUri,
          args.OperationContext.RequestHeaders["caseguid"]);
    };

任何想法在哪里/如何在 CreateDataSource FYI:CaseEntitiesContext 获取 Request 对象

是一个自定义构造函数,它根据 Guid 创建 EF 以确定正确的数据库目录。

I cant seem to figure out to get custom header that I populate on the silverlight client at the time when CreateDataSource is called. I have the following code:

protected override CaseEntitiesContext CreateDataSource()
{
  return new CaseEntitiesContext(CaseGuid, ConnectionString, Provider)
  {
    DefaultContainerName = "CaseEntitiesContext"
  };
}

I get the ConnectionString and Provider from web.config but need to get CaseGuid from RequestHeader.

If I add the following code either in the constructor or in-line the code excutes after the CreateDataSource.

      ProcessingPipeline.ProcessingRequest += (o, args) =>
    {
      CaseGuid = new Guid(args.OperationContext.RequestHeaders["caseguid"]);
      Debug.WriteLine("request case guid:" + args.OperationContext.RequestHeaders["caseguid"]);
      Debug.WriteLine("CaseRequest Processing HTTP {0} request for URI {1} Case Guid {2}",
          args.OperationContext.RequestMethod,
          args.OperationContext.AbsoluteRequestUri,
          args.OperationContext.RequestHeaders["caseguid"]);
    };

Any ideas where / how I can get the Request object at CreateDataSource

FYI:CaseEntitiesContext is a custom constructor that creates the EF based upon Guid to determine the correct db catalog.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扎心 2024-12-05 06:51:11

答案是使用 HttpContext.Current.Request,因为该网站托管在标准 asp.net 中

The answer is to use HttpContext.Current.Request as the website is hosted in standard asp.net

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文