2009-06-16 13 views
1

ASP.NETアプリケーションをビルドしました。ドキュメントを管理するためにサードパーティのCOMオブジェクトSDKを利用する必要があります。アプリケーションの名前は "Interwoven"です。 COMオブジェクトのドキュメントによると、 "アプリケーションごとに複数のIManDMSオブジェクトを作成しないでください"。ASP.NETアプリケーションでCOMアクセスを管理する方法

IManDMSオブジェクトの1つのインスタンスを作成し、それをApplication変数に格納することにしました。ここで私はIManDMSオブジェクトを取得するために使用する機能は次のとおりです。

public static IManDMS GetDMS() 
{ 
    IManDMS dms = HttpContext.Current.Application["DMS"] as IManage.IManDMS; 
    if (dms == null) 
    { 
     dms = new IManage.ManDMSClass(); 
     HttpContext.Current.Application["DMS"] = dms; 
    } 
    return dms; 
} 

… 
// Here is a code snippet showing its use 
IManage.IManDMS dms = GetDMS(); 
string serverName = "myServer"; 
IManSession s = dms.Sessions.Add(serverName); 
s.TrustedLogin(); 

// Do something with the session object, like retrieve documents. 

s.Logout(); 
dms.Sessions.RemoveByObject(s); 
… 

一人だけが、一度に.aspxページを要求している時には、上記のコードは正常に動作します。 2人のユーザーが同時にページを要求すると、私は次のエラーを取得する:

[Sessions ][Add ]Item "SV-TRC-IWDEV" already exists in the collection

どうやらあなたは同時に、同じ名前で、IManDMSオブジェクトに複数のセッションを追加することはできません。これは、アプリケーション全体に対して、いつでも1つのセッションしか開くことができないことを意味します。

同様の問題を経験したことがあり、アプリケーションごとに複数のIManDMSオブジェクトを作成できないと仮定して、この問題を回避する方法を提案できますか?

ありがとうございました。

答えて

2

ロックを使用すると、1つのセッションだけが同時にオブジェクトにアクセスできるようにすることができます。私はIManDSMが何をするかわからないが、エラーがあなたがセッションコレクションに同じ名前を追加している

IManSession s = dms.Sessions.Add(serverName); 

によって引き起こされるようなあなたのコードに基づいて、それが見えます。 SesssionIDのような別の名前をSessionsコレクションに追加できますか?

+0

残念ながら、私は別の名前を追加することはできません。名前は、どのサーバーに接続するかを示します。サーバーは1つだけです。 「ロック」ステートメントを使用すると、このトリックが実行されているようです。助けてくれてありがとう。 –

1

ASP.Netでは、各セッションを自分のアプリケーションとして安全に考えることができます。ここで私はGlobal.asaxファイルでセッションを管理するために、年間のIManage SDKキットに使用しているロジックです:

void Session_Start(object sender, EventArgs e) 
{ 
    // Code that runs when a new session is started 
    ManDMS clientDMS = 
     new ManDMSClass(); 
    clientDMS.ApplicationName = "My App Name"; 
    IManSession clientSession = 
     clientDMS.Sessions.Add(
     ConfigurationManager.AppSettings["DMS Server"]); 
    clientSession.MaxRowsForSearch = 750; 
    clientSession.AllVersions = false; 

    // Save the configured session for use by the user 
    Session.Add("Client.Session", clientSession); 

} 

void Session_End(object sender, EventArgs e) 
{ 
    // Code that runs when a session ends. 
    // Note: The Session_End event is raised only when the sessionstate mode 
    // is set to InProc in the Web.config file. If session mode is set to StateServer 
    // or SQLServer, the event is not raised. 
    IManSession clientSession = 
     (IManSession)Session["Client.Session"]; 
    try 
    { 
     if (clientSession.Connected) 
      clientSession.Logout(); 
    } 
    catch (System.Runtime.InteropServices.COMException cex) 
    { 
     // Ignore COMException if user cannot logout 
    } 
    clientSession.DMS.Close(); 
} 

これに利点はセッションセットアップ/ティアダウンは、ASP.Netセッションにリンクされていることですセッションを適切に管理し、ユーザーにいくつかの大きなスピードの利点を提供します。

あなたは自分のASP.Netページやポストバックでこのコードを使用して、Sessionオブジェクトにアクセスする必要があるとき:

IManSession clientSession = 
     (IManSession)Session["Client.Session"]; 
関連する問題