解決策が見つかりました。興味がある人は、ここにあります:
これはちょっとハックのような感じですが、これは私が思いつく唯一の解決策です。フォーラムSilverlight.netのSally Xuに感謝の気持ちで感謝します。
各ユーザーは複数のサーバー上に複数のデータベースを持つことができるため、初めてDomainServiceを使用する前にConnectionStringを作成する方法を見つける必要がありました。ユーザーがUIから新しいプロジェクトを選択するたびに、私はこのようなクッキーを設定します。
private void SetCookie(string cookieName, string cookieValue)
{
DateTime expireDate = DateTime.Now + TimeSpan.FromDays(1);
string newCookie = cookieName + "=" + cookieValue + ";expires=" + expireDate.ToString("R");
HtmlPage.Document.SetProperty("cookie", newCookie);
}
COOKIENAMEはSelectedProjectId
あるとにcookievalueは私のUIで現在選択されたプロジェクトです。
次に、通常どおり新しいDomainServiceを作成しますが、私はCreateObjectContext()
を上書きします。このメソッドは、初めてDomainServiceオブジェクトを参照するときに呼び出されます。私のオーバーライドは次のようになります。もう一度
protected override ProjectEntities CreateObjectContext()
{
long projectId = -1;
StringBuilder connection;
if (System.Web.HttpContext.Current.Request.Cookies["SelectedProjectId"] != null)
{
projectId = Convert.ToInt64(System.Web.HttpContext.Current.Request.Cookies["SelectedProjectId"].Value);
}
else throw new Exception("Selected Project ID Exception"); // temporary
// Verify this user has access to the DB just in case it's spoofed
// Lookup project ID in my database to get the database name and server name
// Load template connection string found in web.config
// Replace the template holders for SERVER_NAME and DATABASE_NAME with above lookup values
return new ProjectEntities(MyDynamicConnectionString);
}
、これは少しハックですが、それは私が動的に自分のニーズに合わせて接続文字列を作成するために見つけることができる唯一の方法でした。これが他の人に役立つことを願っています...
WCF Data Servicesについてはどうですか? – vorrtex