WCF

Windows Communication Foundation

-Abhishek Tyagi

Boot Camp- Abhishek Tyagi

1

What is WCF?
‡ WCF is way of communicating across components, applications and systems. ‡ It is designed keeping service orientation in mind.

Boot Camp- Abhishek Tyagi

2

So what is a service?
‡ Service is a piece of code, we interact with a message. ‡ They are passive in itself. They wait for client to initiate them by sending them a message. ‡ Services expose one or more end points where message can be sent. ‡ An end point is the access point to the functionality of the service.
Boot Camp- Abhishek Tyagi 3

Why WCF?
‡ WCF unifies the capabilities in ASMX, WSE, Remoting, COM+, and MSMQ. ‡ Therefore the developers has to learn only one programming model to build very effective and industry standard services. ‡ Write service once and expose it many end points. ‡ A lot more options like reliable sessions, lot more security options built in.

Boot Camp- Abhishek Tyagi

4

ABC of WCF
‡ An end point to a service consists of three basic information: ‡ Address: Address of the end point. Where the end point can be found. ‡ Binding: How a client can communicate with the service. ‡ Contract: What operations are available.

Boot Camp- Abhishek Tyagi

5

Contracts in WCF
‡ There are four types of contracts in WCF:
‡ Service Contract: Describe which operations the client can perform on the service. ‡ Data Contract: Define which data types are passed to and from the service. ‡ Fault Contract: Define which errors are raised by the service, and how the service handles and propagates errors to its clients. ‡ Message Contract: Allow the service to interact directly with messages.

Boot Camp- Abhishek Tyagi

6

Creating a WCF Service
To create a WCF web service. We need the following: An Interface containing service contracts.[IHello] A class implementing this interface.[HelloService] An SVC file containing assembly name and the service name.[Hello.svc] ‡ And a configuration file to configure this service so that it can communicate with client. [web.config ] ‡ ‡ ‡ ‡

Boot Camp- Abhishek Tyagi

7

Testing a basic locally hosted WCF Service
‡ Right click on SVC file, select view in browser. The path in the address bar is where is service is hosted. Copy this path. ‡ Open the VS s command prompt type the following: testwcfclient <path of wcf service> In test window the methods in service will appear, click on invoke and test them.

Boot Camp- Abhishek Tyagi

8

Consume a WCF Service
‡ Host the WCF service either on IIS or locally. ‡ Add Service reference in the client project. In service URL give the path where service is hosted. ‡ Create an object of this reference and use the methods the usual way.

Boot Camp- Abhishek Tyagi

9

DEMO
A demo project is added with this presentation.

Boot Camp- Abhishek Tyagi

10

References
‡ ‡ ‡ ‡ ‡ Codeproject.com Msdn.com Dotnetslackers.com Stackoverflow.com SAMS Microsoft WCF

Boot Camp- Abhishek Tyagi

11

Sign up to vote on this title
UsefulNot useful