ksa1
Mobile SEO Guru
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
400 XP
Introduction
In this tutorial you are going to learn WCF one of the key features of Visual Studio. WCF stand for windows communication foundation. WCF is one of powerful introduction of .net framework and provide grate solutions for space left by the web services. Using WCF we can build secure, reliable, transacted solutions that integrate across platforms.
Building a distributed system is a very common task for many programmers. However, doing so involves confronting numerous design challenges. WCF has overcome most of the issues with most of distributed system previously had.
Features of WCF
Before going to code WCF application we should learn some of key concepts of WCF API.
What is end point?
WCF Services exposes a collection of Endpoints, each Endpoint is a portal for communicating with the world. Endpoint is used to identify the service; it is more are like an address for your home. Each endpoint is used to identify the specific service. One service can have multiple endpoints. Client application will use this endpoint for communication with service. All the WCF communications are take place through end point. End point consists of three components. Address, Binding and Contract (ABC )
What is address
Address is the place which has ability to send WCF messages. In another word it has describe WHERE service has hosted
What is binding ?
Binding represent how the message are sent. In other word it specify the type of communication
WCF provides the following transport schemas like: HTTP, TCP, Peer Network, IPC (Inter Process Communicatiion), MSMQ. Basically this describe How end points are communicating
What is Contract ?
It defines “WHAT”. Contract identifies what is exposed by the service.
example of service end point
How to create WCF Application
Open VS 2010
File -> New -> Project
Select Visual C# -> WCF (also select .net framework 4.0) -> select WCF Service Application Template.
Give Name -> EchoService
Click OK.
Adding a Service
Right Click the project folder in Solution Explorer of VS 2010, select -> Add new Item, select -> Web, select -> WCF Service.
Name it -> CustomerService.svc
Adding a DataContract
Right Click the project, select -> Add new Item, select -> web, select -> Class.
Name it -> Customer.cs
Service Interface
Implementing the service.
Usually WCF project can have lots of services but to implement successfully you should have at least one service.
Testing service.
It is very simple. Just press Ctrl + F5 then WCF test client will open. Now you can test you service without implement on server
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Download
In this tutorial you are going to learn WCF one of the key features of Visual Studio. WCF stand for windows communication foundation. WCF is one of powerful introduction of .net framework and provide grate solutions for space left by the web services. Using WCF we can build secure, reliable, transacted solutions that integrate across platforms.
Building a distributed system is a very common task for many programmers. However, doing so involves confronting numerous design challenges. WCF has overcome most of the issues with most of distributed system previously had.
Features of WCF
- 1
- Service Orientation
- Interoperability
- Multiple Message Patterns
- Service Metadata
- Data Contracts
- Security
- Multiple Transports and Encodings
- Reliable and Queued Messages
- Durable Messages
- Transactions
- AJAX and REST Support
- Extensibility
Before going to code WCF application we should learn some of key concepts of WCF API.
What is end point?
WCF Services exposes a collection of Endpoints, each Endpoint is a portal for communicating with the world. Endpoint is used to identify the service; it is more are like an address for your home. Each endpoint is used to identify the specific service. One service can have multiple endpoints. Client application will use this endpoint for communication with service. All the WCF communications are take place through end point. End point consists of three components. Address, Binding and Contract (ABC )
What is address
Address is the place which has ability to send WCF messages. In another word it has describe WHERE service has hosted
What is binding ?
Binding represent how the message are sent. In other word it specify the type of communication
WCF provides the following transport schemas like: HTTP, TCP, Peer Network, IPC (Inter Process Communicatiion), MSMQ. Basically this describe How end points are communicating
What is Contract ?
It defines “WHAT”. Contract identifies what is exposed by the service.
example of service end point
Loading…
localhost
How to create WCF Application
Open VS 2010
File -> New -> Project
Select Visual C# -> WCF (also select .net framework 4.0) -> select WCF Service Application Template.
Give Name -> EchoService
Click OK.
Adding a Service
Right Click the project folder in Solution Explorer of VS 2010, select -> Add new Item, select -> Web, select -> WCF Service.
Name it -> CustomerService.svc

Adding a DataContract
Right Click the project, select -> Add new Item, select -> web, select -> Class.
Name it -> Customer.cs
- using
System
;
- using
System.Collections.Generic
;
- using
System.Linq
;
- using
System.Web
;
- using
System.Runtime.Serialization
;
- namespace
EchoService
- {
- [
DataContract]
- public
class
Customer
- {
- [
DataMember]
- public
string
customerName {
get
;
set
;
}
- [
DataMember]
- public
string
customerAddress {
get
;
set
;
}
- [
DataMember]
- public
int
customerAge {
get
;
set
;
}
- [
DataMember]
- public
string
customerCity {
get
;
set
;
}
- }
- }
Service Interface
- using
System
;
- using
System.Collections.Generic
;
- using
System.Linq
;
- using
System.Runtime.Serialization
;
- using
System.ServiceModel
;
- using
System.Text
;
- namespace
EchoService
- {
- // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "ICustomerService" in both code and config file together.
- [
ServiceContract]
- public
interface
ICustomerService
- {
- [
OperationContract]
- string
GetCustomerName(
string
name)
;
- [
OperationContract]
- string
GetCustomerAddress(
string
address)
;
- [
OperationContract]
- Customer GetCustomerDetails(
)
;
- [
OperationContract]
- List<
Customer>
GetCustomerS(
)
;
- }
- }
Implementing the service.
Usually WCF project can have lots of services but to implement successfully you should have at least one service.
- using
System
;
- using
System.Collections.Generic
;
- using
System.Linq
;
- using
System.Runtime.Serialization
;
- using
System.ServiceModel
;
- using
System.Text
;
- namespace
EchoService
- {
- // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "CustomerService" in code, svc and config file together.
- public
class
CustomerService :
ICustomerService
- {
- public
string
GetCustomerName(
string
name)
- {
- return
string
.
Format
(
"Customer Name Is : {0}"
, name)
;
- }
- public
string
GetCustomerAddress(
string
address)
- {
- return
string
.
Format
(
"Customer Address Is : {0}"
, address)
;
- }
- public
Customer GetCustomerDetails(
)
- {
- Customer newCustomer =
new
Customer(
)
;
- newCustomer.
customerName
=
"Smith"
;
- newCustomer.
customerAddress
=
"River Avanue NW11E London"
;
- newCustomer.
customerAge
=
25
;
- newCustomer.
customerCity
=
"London"
;
- return
newCustomer;
- }
- public
List<
Customer>
GetCustomerS(
)
- {
- List<
Customer>
Clist =
new
List<
Customer>
(
)
;
- Customer newCustomer1 =
new
Customer(
)
;
- newCustomer1.
customerName
=
"Smith"
;
- newCustomer1.
customerAddress
=
"River Avanue NW11E London"
;
- newCustomer1.
customerAge
=
25
;
- newCustomer1.
customerCity
=
"London"
;
- Clist.
Add
(
newCustomer1)
;
- Customer newCustomer2 =
new
Customer(
)
;
- newCustomer2.
customerName
=
"Jhone"
;
- newCustomer2.
customerAddress
=
"No 125/2 Texas US"
;
- newCustomer2.
customerAge
=
40
;
- newCustomer2.
customerCity
=
"Texas"
;
- Clist.
Add
(
newCustomer2)
;
- return
Clist;
- }
- }
- }
Testing service.
It is very simple. Just press Ctrl + F5 then WCF test client will open. Now you can test you service without implement on server

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Download
You must upgrade your account or reply in the thread to view hidden text.