【发布时间】:2011-08-10 23:08:50
【问题描述】:
我有一个 Odata 服务和一个 WPF 客户端应用程序。 一些 Odata 服务实体附有图像(即客户端)。
只要我不应用身份验证,流式传输就可以工作。我可以查看和更改图像。一旦我强制执行身份验证,一切都会按预期工作,给定凭据检查。除了图像之外的所有内容。以下是相关的代码步骤/截图。
窗口构造函数代码
bool iv = System.Web.Security.Membership.ValidateUser("userName", "pass");
ManageService = new InventoryContext(new Uri(...));
ManageService.SendingRequest += new EventHandler<SendingRequestEventArgs (ManageService_SendingRequest);
ManageService_SendingRequest 代码
//attach the authentication cookie to the request header
((HttpWebRequest)e.Request).CookieContainer = ((ClientFormsIdentity)Thread.CurrentPrincipal.Identity).AuthenticationCookies;
获取数据的调用是使用后台工作线程异步进行的 查询方法e()
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(FetchClient);
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(FetchClientsCompleted);
worker.RunWorkerAsync(ClientUUID);
FetchClient
var query = from o in ManageService.Clients where o.ClientUUID.Equals((Guid)e.Argument)
...
e.Result = query;
FetchClients 已完成
var res = e.Result as DataServiceCollection<Client>;
DataContext = res[0]; //this is all working, with and without authentication
//the next line, binding the stream to the image throws 'unauthenticated'
//it works well if authentication is disabled
imgClient.Source = new BitmapImage(ManageService.GetReadStreamUri(DataContext));
如果我调试,通常与任何查询请求一起调用的 SendingRequest 方法不会触发调用 GetReadStreamUri(...)。 这就是我卡住的地方,如何对服务进行身份验证以获取流?
另外,我将 ManageService.GetReadStreamUri(DataContext) 生成的 URI 传递到浏览器中,它可以工作,如果登录,图像会显示在浏览器中。
有人有什么想法吗?
【问题讨论】:
标签: wpf authentication odata wcf-data-services