RemotingServices.GetSessionIdForMethodMessage メソッド
メッセージのセッション ID を取得します。
Public Shared Function GetSessionIdForMethodMessage( _
ByVal msg As IMethodMessage _) As String
[C#]
public static string GetSessionIdForMethodMessage(IMethodMessagemsg);
[C++]
public: static String* GetSessionIdForMethodMessage(IMethodMessage* msg);
[JScript]
public static function GetSessionIdForMethodMessage(
msg : IMethodMessage) : String;
パラメータ
- msg
セッション ID が要求される対象の IMethodMessage 。
戻り値
現在のセッションを一意に識別するセッション ID 文字列。
例外
例外の種類 | 条件 |
---|---|
SecurityException | 直前の呼び出し元に、インフラストラクチャ アクセス許可がありません。 |
解説
同じアプリケーションのオブジェクトに対して同じセッション ID が返される可能性はありますが、このメソッドは異なるリモート アプリケーションの 2 つのオブジェクトに対して同じセッション ID を返すことはありません。
セッションおよびセッション ID の識別の詳細については、「 セッション状態 」を参照してください。
使用例
[Visual Basic, C#, C++] 現在のセッションのセッション ID 文字列を取得する方法の例を次に示します。
Public Sub ProcessMessageStart(requestMessage As IMessage, bClientSide As Boolean, bAsyncCall As Boolean) Implements IDynamicMessageSink.ProcessMessageStart
Console.WriteLine(ControlChars.Cr + "ProcessMessageStart")
Console.WriteLine("requestMessage = {0}", requestMessage)
Try
Console.WriteLine("SessionId = {0}.", RemotingServices.GetSessionIdForMethodMessage(CType(requestMessage, IMethodMessage)))
Catch e As InvalidCastException
Console.WriteLine("The requestMessage is not an IMethodMessage.")
End Try
Dim requestMethodCallMessage As IMethodCallMessage
Try
requestMethodCallMessage = CType(requestMessage, MethodCall)
' Prints the details of the IMethodCallMessage to the console
Console.WriteLine(ControlChars.Cr + "MethodCall details")
Console.WriteLine("Uri = {0}", requestMethodCallMessage.Uri)
Console.WriteLine("TypeName = {0}", requestMethodCallMessage.TypeName)
Console.WriteLine("MethodName = {0}", requestMethodCallMessage.MethodName)
Console.WriteLine("ArgCount = {0}", requestMethodCallMessage.ArgCount)
Console.WriteLine("MethodCall.Args")
Dim o As Object
For Each o In requestMethodCallMessage.Args
Console.WriteLine(ControlChars.Tab + "{0}", o)
Next o
' Sends this method call message to another server to replicate
' the call at the second server
If requestMethodCallMessage.Uri = replicatedServiceUri Then
Dim replicationService As SampleService = CType(Activator.GetObject(GetType(SampleService), replicationServerUrl + replicatedServiceUri), SampleService)
Dim returnMessage As IMethodReturnMessage = RemotingServices.ExecuteMessage(replicationService, requestMethodCallMessage)
' Prints the results of the method call stored in the IMethodReturnMessage.
Console.WriteLine(ControlChars.Cr + "Message returned by ExecuteMessage.")
Console.WriteLine(ControlChars.Tab + "Exception = {0}", returnMessage.Exception)
Console.WriteLine(ControlChars.Tab + "ReturnValue = {0}", returnMessage.ReturnValue)
Console.WriteLine(ControlChars.Tab + "OutArgCount = {0}", returnMessage.OutArgCount)
Console.WriteLine("Return message OutArgs")
For Each o In requestMethodCallMessage.Args
Console.WriteLine(ControlChars.Tab + "{0}", o)
Next o
End If
Catch e As InvalidCastException
Console.WriteLine("The requestMessage is not a MethodCall")
End Try
End Sub 'ProcessMessageStart
[C#]
public void ProcessMessageStart(IMessage requestMessage, bool bClientSide, bool bAsyncCall) {
Console.WriteLine("\nProcessMessageStart");
Console.WriteLine("requestMessage = {0}", requestMessage);
try {
Console.WriteLine("SessionId = {0}.",
RemotingServices.GetSessionIdForMethodMessage((IMethodMessage)requestMessage));
}
catch (InvalidCastException) {
Console.WriteLine("The requestMessage is not an IMethodMessage.");
}
IMethodCallMessage requestMethodCallMessage;
try {
requestMethodCallMessage = (IMethodCallMessage)requestMessage;
// Prints the details of the IMethodCallMessage to the console.
Console.WriteLine("\nMethodCall details");
Console.WriteLine("Uri = {0}", requestMethodCallMessage.Uri);
Console.WriteLine("TypeName = {0}", requestMethodCallMessage.TypeName);
Console.WriteLine("MethodName = {0}", requestMethodCallMessage.MethodName);
Console.WriteLine("ArgCount = {0}", requestMethodCallMessage.ArgCount);
Console.WriteLine("MethodCall.Args");
foreach(object o in requestMethodCallMessage.Args)
Console.WriteLine("\t{0}", o);
// Sends this method call message to another server to replicate
// the call at the second server.
if (requestMethodCallMessage.Uri == replicatedServiceUri) {
SampleService replicationService =
(SampleService)Activator.GetObject(typeof(SampleService),
replicationServerUrl + replicatedServiceUri);
IMethodReturnMessage returnMessage =
RemotingServices.ExecuteMessage(replicationService, requestMethodCallMessage);
// Prints the results of the method call stored in the IMethodReturnMessage.
Console.WriteLine("\nMessage returned by ExecuteMessage.");
Console.WriteLine("\tException = {0}", returnMessage.Exception);
Console.WriteLine("\tReturnValue = {0}", returnMessage.ReturnValue);
Console.WriteLine("\tOutArgCount = {0}", returnMessage.OutArgCount);
Console.WriteLine("Return message OutArgs");
foreach(object o in requestMethodCallMessage.Args)
Console.WriteLine("\t{0}", o);
}
}
catch (InvalidCastException) {
Console.WriteLine("The requestMessage is not a MethodCall");
}
}
[C++]
public:
void ProcessMessageStart(IMessage* requestMessage, bool /*bClientSide*/, bool /*bAsyncCall*/)
{
Console::WriteLine(S"\nProcessMessageStart");
Console::WriteLine(S"requestMessage = {0}", requestMessage);
try
{
Console::WriteLine(S"SessionId = {0}.",
RemotingServices::GetSessionIdForMethodMessage(dynamic_cast<IMethodMessage*>(requestMessage)));
}
catch (InvalidCastException*)
{
Console::WriteLine(S"The requestMessage is not an IMethodMessage*.");
}
IMethodCallMessage* requestMethodCallMessage;
try
{
requestMethodCallMessage = dynamic_cast<IMethodCallMessage*>(requestMessage);
// Prints the details of the IMethodCallMessage* to the console.
Console::WriteLine(S"\nMethodCall details");
Console::WriteLine(S"Uri = {0}", requestMethodCallMessage->Uri);
Console::WriteLine(S"TypeName = {0}", requestMethodCallMessage->TypeName);
Console::WriteLine(S"MethodName = {0}", requestMethodCallMessage->MethodName);
Console::WriteLine(S"ArgCount = {0}", __box(requestMethodCallMessage->ArgCount));
Console::WriteLine(S"MethodCall::Args");
IEnumerator* myEnum = requestMethodCallMessage->Args->GetEnumerator();
while (myEnum->MoveNext())
{
Object* o = __try_cast<Object*>(myEnum->Current);
Console::WriteLine(S"\t {0}", o);
// Sends this method call message to another server to replicate
// the call at the second server.
if (requestMethodCallMessage->Uri == replicatedServiceUri)
{
String* repSvr = String::Format("{0}{1}",
const_cast<String*>(replicationServerUrl),
const_cast<String*>(replicatedServiceUri));
SampleService* replicationService =
dynamic_cast<SampleService*>(Activator::GetObject(__typeof(SampleService),
repSvr));
IMethodReturnMessage* returnMessage =
RemotingServices::ExecuteMessage(replicationService, requestMethodCallMessage);
// Prints the results of the method call stored in the IMethodReturnMessage*.
Console::WriteLine(S"\nMessage returned by ExecuteMessage.");
Console::WriteLine(S"\tException = {0}", returnMessage->Exception);
Console::WriteLine(S"\tReturnValue = {0}", returnMessage->ReturnValue);
Console::WriteLine(S"\tOutArgCount = {0}", __box(returnMessage->OutArgCount));
Console::WriteLine(S"Return message OutArgs");
IEnumerator* myEnum = requestMethodCallMessage->Args->GetEnumerator();
while (myEnum->MoveNext())
{
Object* o = __try_cast<Object*>(myEnum->Current);
Console::WriteLine(S"\t {0}", o);
}
}
}
}
catch (InvalidCastException*)
{
Console::WriteLine(S"The requestMessage is not a MethodCall");
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
.NET Framework セキュリティ:
- SecurityPermission (インフラストラクチャ コードを操作するために必要なアクセス許可)要求値: SecurityAction.LinkDemand; アクセス許可値: SecurityPermissionFlag.Infrastructure
参照
RemotingServices クラス | RemotingServices メンバ | System.Runtime.Remoting 名前空間 | セッション状態