void Initialize() { var currentDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); _serviceEnd1Domain = AppDomain.CreateDomain("ServiceEndDomain1", null, null); var serviceEnd1Asm = AssemblyName.GetAssemblyName(Path.Combine(currentDir, ServiceEnd1Dll)); _serviceEnd1 = (RemoteServiceEnd)_serviceEnd1Domain.CreateInstanceAndUnwrap (serviceEnd1Asm.FullName, ServiceEnd1Type); _serviceEnd2Domain = AppDomain.CreateDomain("ServiceEndDomain2", null, null); var serviceEnd2Asm = AssemblyName.GetAssemblyName(Path.Combine(currentDir, ServiceEnd2Dll)); _serviceEnd2 = (RemoteServiceEnd)_serviceEnd2Domain.CreateInstanceAndUnwrap (serviceEnd2Asm.FullName, ServiceEnd2Type); // 分别在 3 个 AppDomain 中创建 ShuttleDomain _serviceEnd1.CreateShuttleDomain(); _serviceEnd2.CreateShuttleDomain(); var key = Guid.NewGuid().ToString(); _shuttleDomain = ShuttleDomainHelper.Create(key, key); // 分别在 3 个 AppDomain 中注册服务 RegisterServices(); _serviceEnd1.RegisterServices(); _serviceEnd2.RegisterServices(); }
public void CreateShuttleDomain() { // 创建一个 ShuttleDomain var key = this.GetType().Name; _shuttleDomain = ShuttleDomainHelper.Create(key, key); }
public override bool Setup() { _remoteDomain = AppDomain.CreateDomain(Guid.NewGuid().ToString(), null, null); _remoteStarter1 = (RemoteStarter1)_remoteDomain.CreateInstanceAndUnwrap (typeof(RemoteStarter1).Assembly.FullName, typeof(RemoteStarter1).FullName); _remoteStarter1.CreateShuttleDomain(); _remoteStarter1.RegisterServices(); var key = Guid.NewGuid().ToString(); _shuttleDomain = ShuttleDomainHelper.Create(key, key); return(true); }
void Initialize() { _serviceEnd3Domain = AppDomain.CreateDomain("ServiceEndDomain3", null, null); _serviceEnd3 = (RemoteServiceEnd)_serviceEnd3Domain.CreateInstanceAndUnwrap (typeof(RemoteServiceEnd3).Assembly.FullName, typeof(RemoteServiceEnd3).FullName); _serviceEnd4Domain = AppDomain.CreateDomain("ServiceEndDomain4", null, null); _serviceEnd4 = (RemoteServiceEnd)_serviceEnd4Domain.CreateInstanceAndUnwrap (typeof(RemoteServiceEnd4).Assembly.FullName, typeof(RemoteServiceEnd4).FullName); // 分别在 3 个 AppDomain 中创建 ShuttleDomain _serviceEnd3.CreateShuttleDomain(); _serviceEnd4.CreateShuttleDomain(); var key = Guid.NewGuid().ToString(); _shuttleDomain = ShuttleDomainHelper.Create(key, key); }
public override bool Setup() { _remoteDomain = AppDomain.CreateDomain(Guid.NewGuid().ToString(), null, null); _remotingFunctionTest = CreateRemoteFunctionTestObject(); _serviceEnd1 = (RemoteServiceEnd)_remoteDomain.CreateInstanceAndUnwrap (_serviceEnd1AsmName, ServiceEnd1Type); // 创建 ShuttleDomain _serviceEnd1.CreateShuttleDomain(); var key = Guid.NewGuid().ToString(); _shuttleDomain = ShuttleDomainHelper.Create(key, key); // 注册服务 _serviceEnd1.RegisterServices(); return true; }
static void Main(string[] args) { Console.WriteLine("Tests begin..."); // 要使用 JointCode.Shuttle 进行跨 AppDomain 通信,首先必须初始化 ShuttleDomain。 // 这个初始化操作一般在默认 AppDomain 执行,但也可以在其他 AppDomain 中执行,都是一样的。 // To make cross-AppDomain communication with JointCode.Shuttle, initialize the ShuttleDomain at first. // It doesn't matter whether the initialization is done in default AppDomain or any other AppDomains, // but it must be done before any ShuttleDomain instance is created. ShuttleDomain.Initialize(); // 在默认 AppDomain 中,创建一个 ShuttleDomain。 // 事实上,在需要与其他 AppDomain 进行通信的每个 AppDomain 中,都要有一个且只能有一个 ShuttleDomain 对象。 // 尝试在一个 AppDomain 中创建多个 ShuttleDomain 对象时将会抛出异常。 // 该对象用于与其他 AppDomain 中的 ShuttleDomain 对象通信。 // Creating a ShuttleDomain instance in default AppDomain. // Actually, we needs one and only one ShuttleDomain instance in every AppDomain that needs to communicate // with others. Trying to create another ShuttleDomain in the same AppDomain causes exceptions. // The ShuttleDomain instances communicates with each other across AppDomains. var str = Guid.NewGuid().ToString(); var shuttleDomain = ShuttleDomainHelper.Create(str, str); if (CallServicesDefinedInThisAssembly(shuttleDomain) && CallServicesDefinedInAnotherAssembly(shuttleDomain)) { Console.WriteLine("Tests completed..."); } else { Console.WriteLine("Tests failed..."); } shuttleDomain.Dispose(); Console.Read(); }
public void CreateShuttleDomain() { // 创建一个 ShuttleDomain // Create a ShuttleDomain object _shuttleDomain = ShuttleDomainHelper.Create("domain1", "domain1"); }