开发者

One WCF service and multiple database connections

What is the best way to have a WCF host access multiple databases without passing the name after the WCF client has been initiated? I am using DI and want to do something like:

wcfCourseManagement.CourseManagementClient _wcfclient = null;

public WCFCourseRepository(ISystemService systemService): base(systemService)
{
    _wcfclient = new wcfCourseManagement.CourseManagementClient();    
    ServiceEndpoint endpoint = systemService.GetServiceEndpoint("CourseManagement");
    if (endpoint != null)
        _wcfclient.Endpoint.Address = new EndpointAddress(new Uri(endpoint.Endpoint开发者_Go百科));
    if (_wcfclient.GetRemoteSystemID != systemService.ClientSystem.PreferredRemoteSystemID)
        _wcfclient.SetCurrentSystem(systemService.ClientSystem.PreferredRemoteSystemID);
}

The SetCurrentSystem would tell the WCF host that it should rebuild the data repositories if need be. The system ID is just an ID into a config store the server uses to load database configuration information. However, due to the design of the WCF host wiring the "default" SystemID is injected during the parameter-less construction of the host. I want to override that but I do not wish to pass that in every call because that would rip apart the current repository interfaces, shared by client and server code. What is the most direct way to accomplish this type of behavior?


One way to do this is to use the per session instance management. You set which database you want to use in the first call of the session, that one is then used for the entire session.

See: http://msdn.microsoft.com/en-us/magazine/cc163590.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜