创建数据源 WCF 数据服务
我似乎无法弄清楚在调用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案是使用 HttpContext.Current.Request,因为该网站托管在标准 asp.net 中
The answer is to use HttpContext.Current.Request as the website is hosted in standard asp.net