Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8854263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:50:34+00:00 2026-06-14T13:50:34+00:00

I have a class which is basically a message handler, it accepts requests, finds

  • 0

I have a class which is basically a message handler, it accepts requests, finds a processor for that message type, creates an appropriate response and returns it. To this end, I have
created a delegate as follows public delegate Rs ProcessRequest<Rq,Rs>(Rq request); and then inside my class, created a number of supported messages and their process methods. The problem is the main process method which should figure out which process method to use can’t find the method using the GetMethod() method.

Here is the whole code, if you could tell me how to dynamically select the appropriate method and then execute it, thats pretty much what I am looking for.

public delegate Rs ProcessRequest<in Rq, out Rs>(Rq request) where Rq : API.Request where Rs : API.Response;

public class WebSocketServer
{
    private WebSocketMessageHandler messageHander;

    // Incoming message handlers
    public ProcessRequest<InitUDPConnectionRq, InitUDPConnectionRs> ProcessInitUDPConnection;
    public ProcessRequest<ListenHandshakeRq, ListenHandshakeRs> ProcessListenHandshake;
    public ProcessRequest<PresenceChangeRq, PresenceChangeRs> ProcessPresenceChange;
    public ProcessRequest<ChatMessageRq, ChatMessageRs> ProcessChatMessage;
    public ProcessRequest<RDPRequestResponseRq, RDPRequestResponseRs> ProcessRDPRequestResponse;
    public ProcessRequest<RDPIncomingRequestRq, RDPIncomingRequestRs> ProcessRDPIncomingRequest;

    public WebSocketServer(WebSocketMessageHandler handler)
    {
        this.messageHander = handler;
    }

    public void processRequest(API.Request request)
    {
        String resquestType = request.GetType().Name;
        String processorName = resquestType.Substring(0, resquestType.Length - 2);
        API.Response response = null;
        // Do we have a process method for this processor
        MethodInfo methodInfo = this.GetType().GetMethod("Process" + processorName);
        if (methodInfo != null)
        {
             // Execute the method via Invoke...., but code never gets here
        }
        else
        {
            logger.Warn("Failed to find a processor for " + processorName);
            response = new ErrorRs(request.id, "Failed to find a processor for " + processorName);
        }
        sendResponse(response, request);
    }
}

Now I assign those fields to methods as I go, I just can’t dynamically execute them.

// Link into the hooks so we can receive requests
_appContext.ConnectionManager.Connection.webSocketServer.ProcessInitUDPConnection = ProcessInitUDPConnection;
_appContext.ConnectionManager.Connection.webSocketServer.ProcessListenHandshake = ProcessListenHandshake;
_appContext.ConnectionManager.Connection.webSocketServer.ProcessPresenceChange = ProcessPresenceChange;
_appContext.ConnectionManager.Connection.webSocketServer.ProcessChatMessage = ProcessChatMessage;

// 1 method as an example
private PresenceChangeRs ProcessPresenceChange(PresenceChangeRq request)
{
    _appContext.RosterManager.presenceChange(request.user, request.presence);
    return new PresenceChangeRs();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:50:36+00:00Added an answer on June 14, 2026 at 1:50 pm

    Here’s some sample code for the Dictionary usage. Bit too many custom types for me to make sure it compiles fully and tested, but should get you on the right track.

    public class WebSocketServer
    {
        private WebSocketMessageHandler messageHander;
    
        // Incoming message handlers
        private Dictionary<string, System.Delegate> ProcessHandlers = new Dictionary<string, System.Delegate>();
    
        public void RegisterProcessHandler(string name, System.Delegate handler)
        {
            ProcessHandlers.Add(name, handler);
        }
    
        public void processRequest(API.Request request)
        {
            String resquestType = request.GetType().Name;
            String processorName = resquestType.Substring(0, resquestType.Length - 2);
            API.Response response = null;
    
            string processorName = "Process" + processorName;
    
            if (ProcessHandlers.ContainsKey(processorName))
            {
                System.Delegate myDelegate = ProcessHandlers[processorName]; 
                response = (API.Response)myDelegate.DynamicInvoke(request);
            }
            else
            {
                logger.Warn("Failed to find a processor for " + processorName);
                response = new ErrorRs(request.id, "Failed to find a processor for " + processorName);
            }
    
            sendResponse(response, request);
        }
    }
    

    Registration:

    var webSocketServer = _appContext.ConnectionManager.Connection.webSocketServer;
    webSocketServer.RegisterProcessHandler("InitUDPConnection", ProcessInitUDPConnection);
    webSocketServer.RegisterProcessHandler("ListenHandshake", ProcessListenHandshake);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class which is basically a copy of another class. public class
I have a main class(which is basically a netbeans form;drag and drop) from where
I have this script which basically toggles a bgColor class on and off so
I have abstract BaseController, which basically looks like below: public abstract class BaseController :
I have a Log class that has several static methods which help log information
I have a class called GUIMain which registers, creates, and shows a main window
So basically, I have an abstract class which has a unique, incremental ID -
I have defined a ConfigurationProperty class, which is basicly a key-value pair (with key
I have class which have one public method Start , one private method and
I have class LegacyClass which inherits OldBaseClass. I'm considering a change to introduce a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.