【发布时间】:2015-01-07 19:28:26
【问题描述】:
我正在使用 Oracle DataAccess(最后一个),里面有很多数据库用户。因此,我想在我的客户端应用程序 (WPF) 中创建 connectionString 并将其传递给服务器。我在我的服务器中执行以下操作:
protected override POSContext CreateDataSource()
{
HttpRequest req = HttpContext.Current.Request;
if (req.Headers != null && Array.FindIndex(req.Headers.AllKeys, c=>c.Equals("db", StringComparison.OrdinalIgnoreCase)) > 0)
{
string database = req.Headers["db"];
string user = req.Headers["user"];
string pass = req.Headers["pass"];
StringBuilder conexion = new StringBuilder();
conexion.Append("DATA SOURCE=");
conexion.Append(database);
conexion.Append(";USER ID=");
conexion.Append(user);
conexion.Append(";PASSWORD=");
conexion.Append(pass);
if (!string.IsNullOrEmpty(conexion.ToString()))
return new POSContext(conexion.ToString());
}
return null;//new POSContext();
}
在客户端,我有以下代码:
var context = new POS.DataServices.POSContext(new Uri(Storage.Current.UrlService)); // Something like this http://localhost/POService.svc
context.BuildingRequest += (s, args) => //Or SendingRequest2 produces the same result
{
args.Headers.Add("db", Storage.Current.Configuraciones.DB);
args.Headers.Add("user", Storage.Current.Configuraciones.UserName);
args.Headers.Add("pass", Storage.Current.Configuraciones.Password);
};
MessageBox.Show(proxy.POS_CIUDAD.ToList().FirstOrDefault().CIU_DESC); //Alert the city name
调试应用程序时出现错误(请求错误)。我的客户端代码尝试先显示消息,然后转到 BuildingRequest。如何在实体调用之前传递 connectionString?
【问题讨论】:
-
有人吗?用 Oracle 做不到吗?
标签: c# wpf oracle odata wcf-data-services