PC Review


Reply
Thread Tools Rate Thread

Defining a Serviced Component in a dynamic module

 
 
=?Utf-8?B?am9lIG1hbW1h?=
Guest
Posts: n/a
 
      5th Jul 2004
ok, here's the situation.

I am trying to write a class (DynamicServiceGenerator) that creates a dynamic assembly ("DynamicService.dll") which contains a dynamic module that defines an ObjectPooling Attributed type ("DynamicServicedComponent"), deriving from Windows.Enterprise.Services.ServicedComponent, where the "CreationTimeout", "MaxPoolSize" and "MinPoolSize" properties are set at runtime.

The point is, during initialization, I want the DynamicServiceGenerator to configure how many instances of DynamicServicedComponents are allowed to run in the Machines Pooled Object environment.

I would then get a Pooled object by calling
DynamicServiceFactory.GetDynamicServicedComponent()
This should instance a DynamicServicedComponent Type from the dynamically created assembly.

(Does any of this make sense???)

the problem is, when I call:

DynamicServer.DynamicServiceGenerator dsGen = new DynamicServiceGenerator(1,10,30000);
System.EnterpriseServices.ServicedComponent sc = dsGen.GetServicedComponent();

I get an error at 'dsGen.GetServicedComponent()':
The invoked member is not supported in a dynamic module.


Here is my complete code:


using System;
using System.EnterpriseServices;
using System.Reflection;
using System.Reflection.Emit;
using System.IO;
using System.Runtime.InteropServices;


namespace DynamicServer
{

public class DynamicServiceGenerator
{

Type m_DynamicServiceType;



private void CreateDynamicServicedComponentType(int MinObjects, int MaxObjects, int CreationTimeout)
{

// This should basically create an assembly containing the following simple class definition:

// [ ObjectPooling( MinPoolSize= [MinObjects] ,
// MaxPoolSize= [MaxObjects],
// CreationTimeout= [CreationTimeout],
// Enabled = true ) ]
// public class DynamicServicedComponent: ServicedComponent {}
//
// Get the domain

AppDomain myDomain = System.Threading.Thread.GetDomain();

// Load a strong name key pair needed for serviced component assemblies
FileStream fs = new FileStream("dynclass.snk", FileMode.Open);
StrongNameKeyPair kp = new StrongNameKeyPair(fs);
fs.Close();

// Set up the assembly
AssemblyName myAsmName = new AssemblyName();
myAsmName.Name = "DynamicService.dll";
myAsmName.KeyPair = kp;
AssemblyBuilder myAsmBuilder = myDomain.DefineDynamicAssembly( myAsmName, AssemblyBuilderAccess.RunAndSave);

// Define the dynamic module
ModuleBuilder ServicedComponentModule = myAsmBuilder.DefineDynamicModule("DynamicServicedComponent","DynamicServicedComponent.mod", true);

// Define the dynamic type
TypeBuilder ServicedComponentBuilder = ServicedComponentModule.DefineType(
"DynamicService.DynamicServicedComponent",
TypeAttributes.Public ,
typeof(ServicedComponent) );

// Get a constructor for an ObjectPoolingAttribute
Type[] ctorParams = new Type[] {};
ConstructorInfo classCtorInfo = typeof(ObjectPoolingAttribute).GetConstructor(ctorParams);

// Build the ObjectPoolingAttribute Properties
Type myType = typeof(ObjectPoolingAttribute);

System.Reflection.PropertyInfo[] myProps = new System.Reflection.PropertyInfo[]
{
myType.GetProperty("CreationTimeout"),
myType.GetProperty("Enabled"),
myType.GetProperty("MaxPoolSize"),
myType.GetProperty("MinPoolSize") };

// Build the ObjectPoolingAttribute Property Values
object[] propVals = new object[] { CreationTimeout,true, MaxObjects, MinObjects};

// Use a CustomAttributeBuilder to construct the ObjectPoolingAttribute and set the properties
CustomAttributeBuilder myCABuilder = new CustomAttributeBuilder(classCtorInfo, new object[]{} , myProps, propVals);

// Apply the ObjectPoolingAttribute to the Dynamic Type
ServicedComponentBuilder.SetCustomAttribute(myCABuilder);

// Create the type in the assembly
m_DynamicServiceType = ServicedComponentBuilder.CreateType();
}

// Constructor initializes a DynamicService Type with ObjectPooling attribute configuresd and enabled
public DynamicServiceGenerator(int MinObjects, int MaxObjects, int CreationTimeout)
{
CreateDynamicServicedComponentType(MinObjects, MaxObjects, CreationTimeout);
}

// This should instance a DynamicService
public ServicedComponent GetDynamicServicedComponent()
{
Type[] types = new Type[0];
ConstructorInfo ci = m_DynamicServiceType.GetConstructor(types);
return (ServicedComponent) ci.Invoke(null);
}
}
}


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disposing Serviced Component =?Utf-8?B?TWloaXJp?= Microsoft VB .NET 0 21st Oct 2005 07:02 AM
C# COM+ serviced component =?Utf-8?B?bXN1aw==?= Microsoft C# .NET 3 11th Jan 2005 03:59 PM
Serviced Component and ASP.NET Ansari Microsoft ASP .NET 2 20th Oct 2004 06:30 AM
Re: Debugging a c# serviced component Nick Malik Microsoft C# .NET 3 17th Sep 2004 07:52 PM
Looking for Serviced Component Tutorial michael_hk Microsoft Dot NET Framework 2 21st Apr 2004 03:36 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:05 PM.