How to create WCF service without Visual Studio

No.of Views1959
Bookmarked0 times
By  abhi2434   On  29 Nov 2010 04:11:44
Tag : WCF , General
In this article,I am going to implement one of the most basic WCF service without using Visual Studio and show you how to interact with the service
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at



The sophisticated design of WCF made me think of using it always when I need any Web service to be installed in the server. Visual Studio is capable of creating its own configuration settings that helps in developing our application with ease. But what if you don’t have Visual Studio? In this article I am going to implement one of the most basic WCF service without using Visual Studio and show you how to interact with the service.

Server Side

Steps to create the Service definition (Contract):

  1. Open Notepad and add namespace System and System.ServiceModel. We need ServiceModel to specify a WCF service
  2. For WCF service we need to create an interface which will act as a proxy to the client.  From the client, we need to replicate the proxy object and build the same interface again. After we declare the Interface we mark the Interface with ServiceContract, and the method to be exposed to outside using OperationContract.
  3. Next we create a concrete class for the same to define the class implementing the interface.

So our server is Ready.

public interface IOperationSimpleWCF
    [OperationContract]string MySimpleMethod(string inputText);

public class OperationSampleWCF : IOperationSimpleWCF
{public string MySimpleMethod(string inputText)
        Console.WriteLine("Message Received : {0}", inputText);
        Console.WriteLine(OperationContext.Current.RequestContext.RequestMessage.ToString());return string.Format("Message from Server {0}", inputText);

Steps to host the service (Address , Binding):

To host the service in the server you need to know three inputs:

  1. Binding : This indicates how the service will be hosted.  For  basic soap operation with no security we need HttpBinding. We can also use other bindings as well.
  2. Address : Represents the location to host the service. When the service is hosted you can specify the qualified service path where the service will be hosted.
  3. Host the service using ServiceHost and Open the connection.
static void Main(string[] args)

    BasicHttpBinding binding = new BasicHttpBinding();
    Uri serviceUri = new Uri("http://localhost:8000");
    ServiceHost host = new ServiceHost(typeof(OperationSampleWCF), serviceUri);
    host.AddServiceEndpoint(typeof(IOperationSimpleWCF), binding, "OperationService");


    Console.WriteLine("Service is hosted to the Server");


So the uri where the service is hosted is http://localhost:8000/OperationService. You should notice the call AddServiceEndpoint is used to give the qualified address for the service. If you don’t specify AddServiceEndpoint the service will be posted to root path of Uri specified.

To Compile the Server application :

  1. Open Command prompt and navigate to the location where you save the File with code.
  2. To compile the program use csc with /r: to reference the System.ServiceModel.dll using (Say the file we save for code is ServerProgram.cs)
  3. csc /r:” C:\windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\System.ServiceModel.dll” ServerProgram.cs
  4. You will get the program compiled, and produce the Executable. Run the program.

After you run the program it will show the following screen :

Image Loading

Hence the service is running and waiting for the client to receive request. Now its time to create our client application.

Client Side

Steps to create Client Application :

  1. First you need to mimic the ServiceContract interface in the client. If you want to check the Request Body you can use OperationContext.Current.RequestContext.RequestMessage, Or you can directly parse the soap contract using and create the Contract class yourself.
  2. Once we have created the Contract, we create an object of ChannelFactory which actually creates the interface between the client and the server.  The ChannelFactory requires the Binding, and EndPointAddress. The endpoint address for our client will be http://localhost:8000/OperationService
  3. Finally we call CreateChannel to get the actual proxy object which is capable of calling the Remote server.
  4. Compile the Client

Hence when we call the server, the output will be shown on the client.

static void Main(string[] args)
    Console.WriteLine("Press Enter to call Server");

    BasicHttpBinding binding = new BasicHttpBinding();
    ChannelFactory<IOperationSimpleWCF> factory = new ChannelFactory<IOperationSimpleWCF>(binding,new EndpointAddress("http://localhost:8000/OperationService"));

    IOperationSimpleWCF proxy = factory.CreateChannel();string methodFromServer = proxy.MySimpleMethod("Hello");


public interface IOperationSimpleWCF
    [OperationContract]string MySimpleMethod(string inputText);

Once we are done we need to compile the client again using csc.

csc /r:" C:\windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\System.ServiceModel.dll" ClientProgram.cs

Now open the two console side by side, and when you call the server from Client console, it updates the server console. Hence the server been called properly.

Image Loading

If you open the call to OperationContext.Current.RequestContext.RequestMessage.ToString() you can see the Soap envelope that is passed as request to the server from the client. It will look like :

<s:Envelope xmlns:s=\"\">
    <To s:mustUnderstand=\"1\" xmlns=\"\">http://localhost:8000/OperationService</To>
    <Action s:mustUnderstand=\"1\" xmlns=\"\"></Action>
    <MySimpleMethod xmlns=\"\">

Now if you change the Binding from BasicHttpBinding to WSHttpBinding the program outputs the same while the Request body changes with all the support of security features and the message passed within the Soap envelope will automatically been encrypted.

<s:Envelope xmlns:s=\"\" xmlns:a=\"\" xmlns:u=\"\">
    <a:Action s:mustUnderstand=\"1\" u:Id=\"_2\"></a:Action>
    <a:MessageID u:Id=\"_3\">urn:uuid:b3edb9bc-6043-4c05-b540-794e5d61d505</a:MessageID>
    <a:ReplyTo u:Id=\"_4\">
    <a:To s:mustUnderstand=\"1\" u:Id=\"_5\">http://localhost:8000/OperationService</a:To>
    <o:Security s:mustUnderstand=\"1\" xmlns:o=\"\">
      <u:Timestamp u:Id=\"uuid-ce693b53-159f-492e-b79a-f904abb878d8-11\">
c:SecurityContextToken u:Id=\"uuid-ff9818d2-87c0-4daa-ba54-ce07e283ca38-4\" xmlns:c=\"\">
      <c:DerivedKeyToken u:Id=\"uuid-ce693b53-159f-492e-b79a-f904abb878d8-9\" xmlns:c=\"\">
          <o:Reference ValueType=\"\" URI=\"#uuid-ff9818d2-87c0-4daa-ba54-ce07e283ca38-4\" />
      <c:DerivedKeyToken u:Id=\"uuid-ce693b53-159f-492e-b79a-f904abb878d8-10\" xmlns:c=\"\">
          <o:Reference ValueType=\"\" URI=\"#u
uid-ff9818d2-87c0-4daa-ba54-ce07e283ca38-4\" />
      <e:ReferenceList xmlns:e=\"\">
        <e:DataReference URI=\"#_1\" />
        <e:DataReference URI=\"#_6\" />
      <e:EncryptedData Id=\"_6\" Type=\"\" xmlns:e=\"\">
        <e:EncryptionMethod Algorithm=\"\" />
        <KeyInfo xmlns=\"\">
            <o:Reference ValueType=\"\" URI=\"#uuid-ce693b53-159f-492e-b79a-f904abb878d8-10\" />
  <s:Body u:Id=\"_0\">
    <MySimpleMethod xmlns=\"\">

Similar to it, if you have just changed the Binding and the address to NetTcpBinding and net:tcp://localhost:8000 it will work very similarly.

Download Sample Project

Download source files -46 kb


By this way we can create WCF service without using Visual Studio and show you how to interact with the service

Sign Up to vote for this article
About Author
Occupation-Not Provided
Company-Not Provided
Member Type-Senior
Location-Not Provided
Joined date-22 Oct 2009
Home Page-Not Provided
Blog Page-Not Provided
Other popularSectionarticles
There is no comments for this articles.
Leave a Reply
Display Name:
(not display in page for the security purphase)
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top