Accessing WCF service without creating Proxy

Each time when we want to consume a WCF service, we need to create proxy at client side. To create proxy, service must expose metadata endpoint.


1. We create a WCF service

2. Expose metadata endpoint

3. Add service reference at client side to create the proxy.

4. Using the proxy calls the service operation contracts.

Normally we call the service as


Let us assume we want to call the service using channel without creating proxy or adding the service reference. We need to follow the below steps

Step 1

Put all the DataContract or ServiceContract in a separate DLL or class library. Add the reference of System.ServiceModel in class library. And create the service contract as below,


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace ContractDll
    public  interface MyServiceContract

      string GetData(int value);


Assume we have created a service library called ContractDLL

Step 2

Create a WCF Service application and implement the service contract created in step 1. For that add the reference of project created in step 1 in WCF service application.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using ContractDll;

namespace WcfService1
    public class Service1 : MyServiceContract
        public string GetData(int value)
            return string.Format("You entered: {0}", value);


Add the EndPoint in config file.


In above config file

1. ContractDLL.MyServiceContract is name of the service contract exposed.

2. There is no metadata exchange endpoint in the config file.

Full Web.Config is as below,


<?xml version="1.0"?>

    <compilation debug="true" targetFramework="4.0" />
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
      <service name ="WcfService1.Service1" >
        <endpoint address ="" binding ="basicHttpBinding" contract ="ContractDll.MyServiceContract"/>      
            <add baseAddress ="<a href="http://localhost:8181/Service1.svc&quot;/">http://localhost:8181/Service1.svc"/</a>>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <modules runAllManagedModulesForAllRequests="true"/>

Step 3

Create the client. We are creating a console client to consume the service with channel or without creating proxy. So follow the below steps

1. Do not add the service reference.

2. Add the reference of System.ServiceModel.

3. Add the reference of class library created in step1.

Now we need to

1. Create a ChannelFactory


2. Create a binding of the type exposed by service


3. Create EndPoint address


4. Pass Binding and EndPoint address to ChannelFactory


5. Now create the channel as below ,


6. Call the service method on this channel as below ,


So full code of client will be like below


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using ContractDll;

namespace ConsoleApplication1
    class Program
        static void Main(string[] args)
            ChannelFactory<MyServiceContract> factory = null;

                BasicHttpBinding binding = new BasicHttpBinding();
                EndpointAddress address = new EndpointAddress("<a href="http://localhost:4684/Service1.svc">http://localhost:4684/Service1.svc</a>");
                factory = new ChannelFactory<MyServiceContract>(binding, address);
                MyServiceContract channel = factory.CreateChannel();
                string resturnmessage = channel.GetData(9);
            catch (CommunicationException)
                if (factory != null)

            catch (TimeoutException)
                if (factory != null)
            catch (Exception ex)
                if (factory != null)
            Console.WriteLine("Proxy closed");

And we will get output as


6 responses to “Accessing WCF service without creating Proxy”

  1. very nice article. clean and crisp.

  2. But אhe whole idea of WCF is that there is no coupling between the Server and the client. This is why we use metadata endpoint to generate the data and operation in the Client.

  3. Is there a way to identify the contract name if you are consuming a web service already developed (Like SharePoint services)?

  4. Very nice description. Keep it up.

  5. Hi,

    In my opinion you can’t communicate to WCF service without the proxy.

    When you do factory.CreateChannel( ); enables you to create a proxy on the fly.

    2. There is no metadata exchange endpoint in the config file.
    A service has two options for publishing its metadata. You can provide the metadata over the HTTP-GET protocol, or you can use a dedicated endpoint.

    In your config file

    httpGetEnabled is true.

  6. How do we Service Contract and Data contact file. Can you please help

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at