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

  • Home
  • SEARCH
  • 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 713913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:00:54+00:00 2026-05-14T05:00:54+00:00

I have a WCF service (the same one) running on multiple servers, and I’d

  • 0

I have a WCF service (the same one) running on multiple servers, and I’d like to call all instances in parallel from a single client. I’m using ChannelFactory and the interface (contract) to call the service. Each service has a local <endpoint> client defined in the .config file.

What I’m trying to do is build some kind of generic framework to avoid code duplication.

For example a synchronous call in a single thread looks something like this:

    Dim remoteName As String = "endpointName1"
    Dim svcProxy As ChannelFactory(Of IMyService) = New ChannelFactory(Of IMyService)(remoteName)
    Try
        svcProxy.Open()
        Dim svc As IMyService = svcProxy.CreateChannel()
        nodeResult = svc.TestRemote("foo")
    Finally
        svcProxy.Close()
    End Try

The part I’m having difficulty with is how to specify and actually invoke the actual remote method (eg “TestRemote”) without having to duplicate the above code, and all the thread-related stuff that invokes that, for each method.

In the end, I’d like to be able to write code along the lines of (consider this psuedo code):

Dim results as Dictionary(Of Node, ExpectedReturnType) 
results = ParallelInvoke(IMyService.SomeMethod, parameter1, parameter2) 

where ParallelInvoke() will take the method as an argument, as well as the parameters (paramArray or object() .. whatever) and then go run the request on each remote node, block until they all return an answer or timeout, and then return the results into a Dictionary with the key as the node, and the value as whatever value it returned.

I can then (depending on the method) pick out the single value I need, or aggregate all the values from each server together, etc.

I’m pretty sure I can do this using reflection and InvokeMember(), but that requires passing the method as a string (which can lead to errors like calling a non-existing method that can’t be caught at compile time), so I’d like to see if there is a cleaner way to do this.

Thanks

  • 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-05-14T05:00:55+00:00Added an answer on May 14, 2026 at 5:00 am
     public static TResult MakeCall<TService, TResult>(Func<TService, TResult> method,  string remoteName)
            {
                // try not to create the factory object for each call, it can be a singleton
                var factory = GetFactory<TService>(remoteName);
                TService proxy = default(TService);
                TResult result = default(TResult);
                try
                {
                    proxy = factory.CreateChannel();
                    result = method(proxy);
                }
                finally
                {
                    // proxy disposal is a bit tricky in WCF and you might need to read more about Close/Abort
                     Close(proxy);                    
    
                }
                return result;
            }
    

    which lets you call any method on any interface without having to duplicate the plumbing code.

    public interface IMyService
            {
                int Sum(int a, int b);
                int Max(int a, int b);
            }
    

    public interface IMyService2
    {
    bool Test(string value);
    }

       static void Main(string[] args)
            {
                var a = 12;
                var b = 12;
                var r1 = MakeCall((IMyService proxy) => proxy.Sum(a, b),  "endpoint1");
                var a1 = 12;
                var b1 = 14;
                var r2 = MakeCall((IMyService proxy) => proxy.Max(a1, b1), "endpoint1");
                var r3 = MakeCall((IMyService2 proxy) => proxy.Test("test"), "endpoint2");
            }
    

    You can use MakeCall as a building block for your end solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of remote machines all running the same WCF service over
I have WCF service running from within a Windows Service. This is working fine
I have a WCF client (running on Win7) pointing to a WebSphere service. All
I have 3 projects in the same solution - one exposes a WCF service
Ok we have a WCF service running on one machine on IIS6 + server2003
I have a IIS-Hosted WCF service running on one server and a windows service
I have a wcf self-hosted service running as windows service, serving multiple win/web clients
We have a requirement to call a WCF service from another WCF Service. To
I have a need to run multiple WCF services at the same time, from
I have a wcf service defined like this: [OperationContract] [WebInvoke(Method = POST, ResponseFormat =

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.