 
  
    Custom Search
  
Friday, August 15, 2008
Create WCF Service with TCP Binding
Hey guys,
Lets start with creating a simple WCF(Windows Communication Foundation) Service with TCP binding.
Environment i'm using:
>Windows server 2008
>Visual Studio 2008
>> Language: C#
>IIS 7.0
Lets start with small application using Service, Client & Library projects under single solution.
Putting stuff in library project just because of broad understanding of WCF & its features. So, lets have little idea about what/how we are gonna do this task.
Lets start with creating a simple WCF(Windows Communication Foundation) Service with TCP binding.
Environment i'm using:
>Windows server 2008
>Visual Studio 2008
>> Language: C#
>IIS 7.0
Lets start with small application using Service, Client & Library projects under single solution.
Putting stuff in library project just because of broad understanding of WCF & its features. So, lets have little idea about what/how we are gonna do this task.
Start with project 'Library', which will have all the contracts & business logic. Project 'Service' will have services(.svc) & configuration files which will points to library for consuming contracts.
Project 'Client' is the consumer, who will consume the WAS hosted services.
Project 'Provider' is the service provider, eventually a WAS hosted service using IIS 7.0. Later on, we will discuss self hosted WAS services in detail.
So Lets begin with Contracts & business logic under Library project [C#>Windows>Class Library]:
> Rename Class1.cs as SampleService.cs
> Add new item as ISampleContract.cs
> Add new item as Customer.cs
> Add reference of System.Runtime.Serialization.Dll
> Add reference of System.ServiceModel
Lets take a look towards Customer.cs code which, we will use for DataMember & DataContract declaration
Customer.cs:
using System;
using System.Runtime.Serialization;
using System.ServiceModel;
namespace Library
{
    [Serializable]
    [DataContract]
    public class Customer
    {
        public Customer() { }
        [DataMember]
        public int CutomerID;
        [DataMember]
        public string CustomerName;
        [DataMember]
        public string CustomerAddress;
        public int GetCustomerID(string customerName)
        {
            //Code snippet which get data from database
            CutomerID = 10;
            return CutomerID;
        }
        public string GetCustomerName(string custromerID)
        {
            //Code snippet which get data from database
            CustomerName = "Hello Customer";
            CustomerAddress = "Customer Address";
            return CustomerName;
        }
    }
}
I declared class as 'Serializable' which, we will discuss later. 
ISampleService.cs:
SampleService.cs
to be Continued....
Subscribe to Comments [Atom]

