Agenda
•.NET Framework 3.5 Overview
•Web Services Overview
•Remoting Overview
•WCF Overview
•Elements of WCF & WCF Architecture
•Different Types of WCF Services
•Creating your first WCF Service
•Service Endpoint Configurations
•Service and Data contracts
•Consuming your WCF Service from Clients
•Tools used in creating Proxies
.NET Framework 3.5
Overview
Web Services Overview
Windows Communication
Foundation (WCF)
•WCF is Microsoft’s unified programming model that
combines the best of .NET distributed systems
technologies such as:
- ASP.NET Web Services (ASMX)
- .NET Remoting (Remoting)
- Enterprise Services (COM+)
- Web Services Enhancements (WSE)
- Microsoft Message Queuing (MSMQ)
- Representational State Transfer (REST)
What WCF Provides?
•Unification of Microsoft’s Distributed Computing
Technologies
•Interoperability with Applications Built on Other
Technologies
•Interoperability with Other Web Services Platforms
•Interoperability with Microsoft’s Pre-WCF Technologies
•Explicit Support for Service-Oriented Development
• Framework for building services that process XML
messages
•Allows to transmit messages using different transport
protocols (such as HTTP, TCP, and MSMQ) and using
different XML representations (such as text, binary, or
MTOM)
WCF - Unified
Programming Model
WCF - Unified Programming Model
ABCs of Programming
WCF
WCF End Points
The Structure of an
Endpoint
Address:
The address uniquely identifies the endpoint and
tells potential consumers of the service where it is
located.
EndPoint usingwsHttpBinding
•<add
baseAddress="http://localhost:8550/YourNameSpace.You
rServiceCV/" />
Endpoint using netNamedPipeBinding
•<add
baseAddress="net.pipe://localhost/YourNameSpace.YourS
erviceCV/" />
WCF Bindings
Binding Configuration Element Description
BasicHttpBinding
<basicHttpBinding> A binding that is suitable for communicating with WS-Basic
Profile conformant Web services, for example, ASP.NET Web
services (ASMX)-based services. This binding uses HTTP as
the transport and text/XML as the default message encoding.
WSHttpBinding
<wsHttpBinding>
A secure and interoperable binding that is suitable for non-
duplex service contracts.
WSDualHttpBinding
<wsDualHttpBinding>
A secure and interoperable binding that is suitable for duplex
service contracts or communication through SOAP
intermediaries.
WSFederationHttpBinding
<wsFederationHttpBinding>
A secure and interoperable binding that supports the WS-
Federation protocol that enables organizations that are in a
federation to efficiently authenticate and authorize users.
NetTcpBinding <netTcpBinding>
A secure and optimized binding suitable for cross-machine
communication between WCF applications.
Bindings are used to specify the transport, encoding, and protocol details
required for clients and services to communicate with each other.
To generate the underlying wire representation of the endpoint, most of the
binding details must be agreed upon by the parties that are communicating.
WCF Bindings
Binding Configuration Element Description
NetMsmqBinding
<netMsmqBinding>
A queued binding that is suitable for cross-machine
communication between WCF applications.
NetPeerTcpBinding
<netPeerTcpBinding> A binding that enables secure, multiple machine
communication.
MsmqIntegrationBinding
<msmqIntegrationBinding>
A binding that is suitable for cross-machine communication
between a WCF application and existing Message Queuing
applications.
BasicHttpContextBinding
<basicHttpContextBinding>
A binding that is suitable for communicating with WS-Basic
Profile conformant Web services that enables HTTP cookies
to be used to exchange context.
NetTcpContextBinding
<netTcpContextBinding>
A secure and optimized binding suitable for cross-machine
communication between WCF applications that enables SOAP
headers to be used to exchange context.
WebHttpBinding
<webHttpBinding> A binding used to configure endpoints for WCF Web services
that are exposed through HTTP requests instead of SOAP
messages.
WSHttpContextBinding
<wsHttpContextBinding>
A secure and interoperable binding that is suitable for non-
duplex service contracts that enables SOAP headers to be
used to exchange context.
CustomBinding Developer decides Developer decides
ServiceContract
Use the ServiceContract attribute on an interface
(or class) to define a service contract.
ServiceContract combined with an endpoint and
address exposes the service to the client
Service class will implement a ServiceContract –
Implementing the interface marked with
ServiceContract attribute
Example:-
[ServiceContract]
public interface IMyFirstService
{
//TODO : Define your Operations here
}
OperationContract
OperationContract attribute is used in the class
(or interface) methods to define the contract's
service operations
OperationContract exposes the service operation
to the client
All Service Operations (methods) to be exposed
to the clients should be marked with
OperationContract attribute
Example:-
[ServiceContract]
public interface IMyFirstService
{
[OperationContract]
string GetData(int value);
}
DataContract &
DataMember
Agreement between the client and the service
that describes the data to be exchanged
DataContract Serializer to serialize and de-
serialize data
Serialize and De-Serialize is nothing but
converting the data to and from xml
In order to tell the serialization engine, we need
to use DataContract attribute as a prefix for the
class and DataMember attribute prefix for the
property(data member)