2011-08-08 90 views
0

我似乎無法弄清楚在調用CreateDataSource的時候,我在silverlight客戶端上填充自定義頭。我有以下代碼:CreateDataSource WCF DataServices

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

我得到的ConnectionString並提供從web.config中,但需要從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

得到Request對象FYI:CaseEntitiesContext是創建基於的GUID EF確定正確的數據庫目錄的自定義構造函數。

回答

0

答案是使用HttpContext.Current.Request作爲網站託管在標準的asp.net

相關問題