Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Could be the most 'meta' class I ever wrote... or a coding horror?

Could be the most 'meta' class I ever wrote... or a coding horror?

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharprubywcfquestioncareer
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kieryn Phipps
    wrote on last edited by
    #1

    ServiceCallInfo is actually a DataContract. Yes... I have actually implemented a service that can call any other service it happens to find in it's configuration. I'm sure none of this would be necessary in a dynamic language like Ruby, however what other framework/language provides such a comprehensive and flexible service framework like WCF? I wasn't sure if this should go in "Clever Code" or "Hall of Shame" for it's meta-ness. I put it here, because I like to doubt myself :-) Right now it depends on all the service contracts being contained in one interface assembly though... I suppose I could also pass in the assembly name containing the contract and have it dynamically try to find or load the assembly too. Or would that be too far?

    internal class ReflectedServiceChannelMethod
    {
    private static readonly Assembly InterfaceAssem = Assembly.GetAssembly(typeof(IGeneralLookupService));
    private readonly Type _contractType;
    private readonly Type _channelFactoryType;
    private readonly object _channelFactory;
    private readonly MethodInfo _createChannelMethod;
    private readonly MethodInfo _callMethodInfo;
    private readonly ParameterInfo[] _methodParams;

        public ReflectedServiceChannelMethod(string interfaceName, string methodName)
        {
            \_contractType = \_interfaceAssem.GetType(interfaceName);
            \_channelFactoryType = typeof(EdsChannelFactory<>).MakeGenericType(\_contractType);
            \_callMethodInfo = \_contractType.GetMethod(methodName);
            \_methodParams = \_callMethodInfo.GetParameters();
            var channelFactoryConstructor = \_channelFactoryType.GetConstructor(new Type\[\] {});
            \_channelFactory = channelFactoryConstructor.Invoke(new object\[\] {});
            \_createChannelMethod = \_channelFactoryType.GetMethod("CreateDefaultChannel", new Type\[\]{});
        }
    
        public object CallService(ServiceCallInfo job)
        {
            object channel = null;
            try
            {
                channel = \_createChannelMethod.Invoke(\_channelFactory, new object\[\] { });
                var parameters = new List<object>();
                foreach (var methodParam in \_methodParams)
                {
                    object value = null;
                    var paramType = methodParam.ParameterType.MakeByValType();
                    if (job.Parameters != null)
                    {
                        ParameterInfo param = me
    
    G 1 Reply Last reply
    0
    • K Kieryn Phipps

      ServiceCallInfo is actually a DataContract. Yes... I have actually implemented a service that can call any other service it happens to find in it's configuration. I'm sure none of this would be necessary in a dynamic language like Ruby, however what other framework/language provides such a comprehensive and flexible service framework like WCF? I wasn't sure if this should go in "Clever Code" or "Hall of Shame" for it's meta-ness. I put it here, because I like to doubt myself :-) Right now it depends on all the service contracts being contained in one interface assembly though... I suppose I could also pass in the assembly name containing the contract and have it dynamically try to find or load the assembly too. Or would that be too far?

      internal class ReflectedServiceChannelMethod
      {
      private static readonly Assembly InterfaceAssem = Assembly.GetAssembly(typeof(IGeneralLookupService));
      private readonly Type _contractType;
      private readonly Type _channelFactoryType;
      private readonly object _channelFactory;
      private readonly MethodInfo _createChannelMethod;
      private readonly MethodInfo _callMethodInfo;
      private readonly ParameterInfo[] _methodParams;

          public ReflectedServiceChannelMethod(string interfaceName, string methodName)
          {
              \_contractType = \_interfaceAssem.GetType(interfaceName);
              \_channelFactoryType = typeof(EdsChannelFactory<>).MakeGenericType(\_contractType);
              \_callMethodInfo = \_contractType.GetMethod(methodName);
              \_methodParams = \_callMethodInfo.GetParameters();
              var channelFactoryConstructor = \_channelFactoryType.GetConstructor(new Type\[\] {});
              \_channelFactory = channelFactoryConstructor.Invoke(new object\[\] {});
              \_createChannelMethod = \_channelFactoryType.GetMethod("CreateDefaultChannel", new Type\[\]{});
          }
      
          public object CallService(ServiceCallInfo job)
          {
              object channel = null;
              try
              {
                  channel = \_createChannelMethod.Invoke(\_channelFactory, new object\[\] { });
                  var parameters = new List<object>();
                  foreach (var methodParam in \_methodParams)
                  {
                      object value = null;
                      var paramType = methodParam.ParameterType.MakeByValType();
                      if (job.Parameters != null)
                      {
                          ParameterInfo param = me
      
      G Offline
      G Offline
      Gary R Wheeler
      wrote on last edited by
      #2

      ObjectServiceFactoryServiceObjectAutomationLinkFactoryServiceFactoryObjectMetaObjectBuilderFactory.

      Software Zen: delete this;

      OriginalGriffO 1 Reply Last reply
      0
      • G Gary R Wheeler

        ObjectServiceFactoryServiceObjectAutomationLinkFactoryServiceFactoryObjectMetaObjectBuilderFactory.

        Software Zen: delete this;

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        Gary R. Wheeler wrote:

        ObjectServiceFactoryServiceObjectAutomationLinkFactoryServiceFactoryObjectMetaObjectBuilderFactory.

        You forgot "GoldProTeamEdition"...

        Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups