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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:31:09+00:00 2026-06-19T00:31:09+00:00

Basically I have the code from MSDN. The code is: using System; using System.ServiceModel;

  • 0

Basically I have the code from MSDN.

The code is:

using System;
using System.ServiceModel;

// This code generated by svcutil.exe.
[ServiceContract()]
interface IMath
{
     [OperationContract()]
     double Add(double A, double B);
}

public class Math : IMath
{
public double Add(double A, double B) 
{
    return A + B;
}
}

public sealed class Test
{
    static void Main()
   {
       // Code not shown.
   }

public void Run()
{
    // This code is written by an application developer.
    // Create a channel factory.
    BasicHttpBinding myBinding = new BasicHttpBinding();

    EndpointAddress myEndpoint = new EndpointAddress("http://localhost/MathService/Ep1");

    ChannelFactory<IMath> myChannelFactory = new ChannelFactory<IMath>(myBinding, myEndpoint);

    // Create a channel.
    IMath wcfClient1 = myChannelFactory.CreateChannel();
    double s = wcfClient1.Add(3, 39);
    Console.WriteLine(s.ToString());
((IClientChannel)wcfClient1).Close();

    // Create another channel.
    IMath wcfClient2 = myChannelFactory.CreateChannel();
    s = wcfClient2.Add(15, 27);
    Console.WriteLine(s.ToString());
((IClientChannel)wcfClient2).Close();
myChannelFactory.Close();
}
}

However based on my superficial understanding, it is a self host WCF. The above code is combining service code and client code together.
If the WCF is host in a server, we don’t know its internal struture at all. Then how to consume it in client side?
I used the code

ChannelFactory<IMath> myChannelFactory = new ChannelFactory<IMath>(myBinding, myEndpoint);

But intellisense doesn’t know IMath at all.
I am not strong on proxy, ChannelFactory etc. Now my question is that if the service IMath is host at http://www.someserver/IMath.svc, how to write code in client side to consume it?

Please don’t think adding web reference to the clent…

updated:
In the service wsdl:
I have something like:

<wsdl:binding name="BasicHttpBinding_iMath" type="tns:iMath">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
 - <wsdl:operation name="Add">
 <soap:operation soapAction="http://tempuri.org/iMath/add" style="document" /> 
 - <wsdl:input>
<soap:body use="literal" /> 
 </wsdl:input>
- <wsdl:output>
 <soap:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
- <wsdl:operation name="LoadUnbillsFromOrion">
  <soap:operation soapAction="http://tempuri.org/iMath/LoadUnbillsFromOrion" style="document" /> 
- <wsdl:input>
  <soap:body use="literal" /> 
  </wsdl:input>
- <wsdl:output>
   <soap:body use="literal" /> 
   </wsdl:output>
   </wsdl:operation>
  </wsdl:binding>
 - <wsdl:service name="Math">
 - <wsdl:port name="BasicHttpBinding_iMath" binding="tns:BasicHttpBinding_iMath">
   <soap:address location="http://wsvc01/Imath.svc" /> 
  </wsdl:port>
 </wsdl:service>
  • 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-19T00:31:10+00:00Added an answer on June 19, 2026 at 12:31 am

    Basically, all you need to know is a binding and endpoint address on your client side.

    To consume a WCF service you need to create a proxy. Unless you specifically need a reason to the ChannelFactory, it’s probably easier to create a “Client” class that inherits from ClientBase<>.

    public class Client : ClientBase<IMath>
    {
        private static Binding MyBinding { get; set; }
    
        private static EndpointAddress MyEndpoint { get; set; }
    
        public Client() : base(MyBinding, MyEndpoint)
        {
        }
    
        public double Add(double a, double b)
        {
            Open();
            var c = Channel.Add(a, b);
            Close();
    
            return c;
        }
    }
    

    You then create an instance of your proxy suppling it an endpoint and binding in the constructor (or have the proxy automatically do it in it’s default, you can do whatever you want) to communicate with your WCF Service. You then just Open and Close your client object and then Call your Client.IMathOperation to perform an operation on the service. The ClientBase<> will handle Channel creation, disposing, pooling etc.

    Client proxy = new Client();
    proxy.Add(1, 2);
    

    You’ll probably want to put in various wrapper and helper classes on the Client side to handle exceptions, testing your connection before trying to access it, encapsulating opening and closing channels etc. to make it less verbose to use on the client-side.

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

Sidebar

Related Questions

This is a follow up from my previous question I have this code basically
I have (basically) this code - <script type=text/javascript language=javascript> $(document).ready(function() { $(#loadDiv).load(mypage.html, function(){ alert($(#someText).text())
I have this horribly stripped delphi code that basically login to server, save cookie
I have this small piece of code that basically takes a list and runs
So I basically have this code: @render_to('hello/home.html') def home(request): info = Info.objects.get(pk=1) if request.method
I have code like the one in this question, basically a UI-thread that gets
So I have this code. Basically it should be able to take a stock
I need some help with this. Basically I have the following code which I
this kind of follows on from another question of mine. Basically, once I have
I know this is a messy implementation, but I basically have this code (I

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.