本文整理匯總了C#中System.Runtime.Remoting.Messaging.CallContext.GetData方法的典型用法代碼示例。如果您正苦於以下問題:C# CallContext.GetData方法的具體用法?C# CallContext.GetData怎麽用?C# CallContext.GetData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Runtime.Remoting.Messaging.CallContext
的用法示例。
在下文中一共展示了CallContext.GetData方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: HelloServiceClass
//引入命名空間
using System;
using System.Text;
using System.Runtime.Remoting.Messaging;
using System.Security.Principal;
using System.Security.Permissions;
public class HelloServiceClass : MarshalByRefObject {
static int n_instances;
int instanceNum;
public HelloServiceClass() {
n_instances++;
instanceNum = n_instances;
Console.WriteLine(this.GetType().Name + " has been created. Instance # = {0}", instanceNum);
}
~HelloServiceClass() {
Console.WriteLine("Destroyed instance {0} of HelloServiceClass.", instanceNum);
}
[PermissionSet(SecurityAction.LinkDemand)]
public String HelloMethod(String name) {
//Extract the call context data
LogicalCallContextData data = (LogicalCallContextData)CallContext.GetData("test data");
IPrincipal myPrincipal = data.Principal;
//Check the user identity
if(myPrincipal.Identity.Name == "Bob") {
Console.WriteLine("\nHello {0}, you are identified!", myPrincipal.Identity.Name);
Console.WriteLine(data.numOfAccesses);
}
else {
Console.WriteLine("Go away! You are not identified!");
return String.Empty;
}
// calculate and return result to client
return "Hi there " + name + ".";
}
}