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 8595437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:25:58+00:00 2026-06-12T00:25:58+00:00

I have an interface in C#, something like this: interface ITest { int Method1(int

  • 0

I have an interface in C#, something like this:

interface ITest
{
    int Method1(int something);
}

All methods have parameters of basic types (integer, string, enum).

Now I want the implementation and the client to run on different machines communicating over a socket. What I could do manually is to make an implementation like this:

class Test : ITest
{
    int Method1(int something)
    {
        m_Serializer.Serialize(something, m_Socket);
        int result = (int)m_Serializer.Deserialize(m_Socket, typeof(int));
        return result;
    }
}

Is there a way to automate it, i.e. to generate such a wrapper for a given interface automatically?

I could generate it manually via Reflection.Emit, but that’s quite complex. Any easy way?

  • 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-12T00:26:00+00:00Added an answer on June 12, 2026 at 12:26 am

    WCF (Windows Communication Foundation) would be what you’re looking for. It does pretty much exactly this – it does however have a somewhat steep learning curve.

    I like to think of it as a framework that automatically generates a network “protocol” that is defined by your interface – the service contract. The “protocol” is also independent of the underlying network transport – there are bindings for raw TCP, HTTP, HTTPS, all with different use cases in mind.

    You never have to actually care about what the network traffic actually looks like at the protocol or byte level – the whole lot is done for you seamlessly.

    Clever stuff, worth learning.

    Complete example of a WCF client and server over plain TCP, with no config files (all programmatic)

    Create a class library which will be shared between two other programs, your client and server, containing an interface.

    [ServiceContract]
    public interface IMyApi
    {
        [OperationContract]
        string SayHello(string s);
    }
    

    In program one, the server:
    Add a reference to the class library above.

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class MyApi : IMyApi
    {
        public string SayHello(string s)
        {
            return "Hello " + s;
        }
    }
    
    static void Main()
    {
        var api = new MyApi();
        var svcHost = new ServiceHost(api, new Uri("net.tcp://localhost:12345/MyService"));
        svcHost.Open();
        Thread.CurrentThread.Join();
    }
    

    Program two, the client:
    Add a reference to the class library above.

    static void Main()
    {
        var binding = new NetTcpBinding();
        var endpoint = new EndpointAddress("net.tcp://localhost:12345/MyService");
        var cf = new ChannelFactory<IMyApi>(binding, endpoint);
        var client = cf.CreateChannel();
    
        Console.WriteLine(client.SayHello("Tom")); // output on the console should be "Hello Tom"
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a generic interface for a mathematics library, something like this: [ContractClass(typeof(MathsDoubleContracts))] public
In my interface I have a list of text boxes, something like this :
Let's say I have a service whose interface is something like this: public interface
I have a marker interface something like this: [AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)] public class MyAttribute
In Java, if I have an interface, I can do something like this: blah.setOnClickListner(new
In C++ methods can have optional arguments, like this: void myFunction (int arg1, int
I have something that looks like the following: [CoolnessFactor] interface IThing {} class Tester
I have a number of class, all with exactly the same interface. This interface
I have a service interface with many methods, all of which take a Request
Simple case: I have an interface for logging messages, like this: public interface ILogger

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.