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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:51:14+00:00 2026-05-12T18:51:14+00:00

I am trying to consume a wcf rest service via reflection if possible. Take

  • 0

I am trying to consume a wcf rest service via reflection if possible. Take a look at the code below:

    public static object WCFRestClient<T>(string method, string uri, params object[] args)
    {        
        object o;
        object ret;
        using (ChannelFactory<T> cf = new ChannelFactory<T>(new WebHttpBinding(), uri))
        {                
            T contract = cf.CreateChannel();
            ret = contract.GetType().GetMethod(method).Invoke(o, args);

        }
        return ret;
    }

As you see it is a generic method that takes T at run time… my trouble is, I am not sure if I can really reflect on the channel object I am creating above…. Lets say I do, then the trouble starts when I want to create an object instance… Since I can’t create an object instance from an interface…

I would also be happy to hear about if there is any other way to accomplish this? But I prefer to use channel mechanism if I can.

  • 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-12T18:51:14+00:00Added an answer on May 12, 2026 at 6:51 pm

    In general, creating a ChannelFactory for every operation is expensive. You should avoid that if possible. The using pattern is also problematic for ICommunicationObject types in WCF, since Dispose() generally corresponds to Close() which is a blocking/exception-throwing call. You will want to call Close() explicitly instead and handle TimeoutException and CommunicationException.

    Aside from that, your approach would work. If you use ChannelFactory<T>.CreateChannel, it will create a transparent proxy object of type T which could be called upon via reflection if you want. So you won’t have to worry about creating an object from the contract interface — WCF already does that.

    In your code sample, make sure to replace the o with contract and you should get the results you expect.

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

Sidebar

Related Questions

I've been trying to consume a .net WCF rest service using JAX-WS lately. Due
I'm trying to consume a rest service(wcf) using restsharp This is my service [ServiceContract]
I am trying to consume my newly setup RESTful WCF service, located at [http://196.34.92.60/api/api/v1/public.svc/getoperators]
Im trying to consume Wcf from Android , my code private final static String
I am trying to consume a WCF service on a remote server. I can
I'm trying to consume a WS-Security enabled service with WCF. Authentication works using a
I'm having a problem with a WCF service trying to consume it from Java.
am trying to create WCF client to consume the service, which contains messages. So
I am trying to build a REST & json based WCF service that takes
I am trying to consume a WCF service in a class library by adding

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.