开发者

Need Help with Dynamic Connection Strings in WCF Data Services... CreateDataSource() being called before OnRequest()?

I have a working WCF Data Service built on a Linq2Sql data provider. Things are looking good so far.

The client app that hits the service accepts a user and password which I authenticate at the server. However, on the server-side the data for each client is stored in a separate client-specific database. So, I need to be able to change the connection string 开发者_如何学运维for the data provider after the user has authenticated/identified themselves.

I overrode the data context's CreateDataSource() method (which appears to give me the ability to change the connection string dynamically, which is good). However, during debugging, I see that CreateDataSource() fires before OnRequest()... OnRequest() is where I handle user authentication, so I don't know who they are yet or whether they're authorized at the time that CreateDataSource() fires.

Is there another way to handle the dynamic connection string issue, without having CreateDataSource() called before my request handler? Or, less optimally, is there a way to delay, or trigger the service/data provider to call CreateDataSource() again after authentication, so I can tell who the user is, and construct the proper connection string?

Thanks!


Is there a reason why you can do the authentication in CreateDataSource method - First do the authentication, and then accordingly create the datasource with the appropriate connection string.

CreateDataSource method is called everytime to create the new instance of your data source.

Thanks Pratik

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜