6461a 01
6461a 01
6461a 01
Windows®
Communication
Foundation
Module 1: Getting Started with Windows
Communication Foundation
• Designing an Application to Be Part of a Service Oriented
Architecture (SOA)
• Overview of WCF Architecture
• Applications become:
User interface flows that make use of services
Longer-running workflows that make use of services
Portals and mash-ups that make use of services
1
Get commitment for the effort required
2
Gather the services
3
Group related business functions together
Services, Components, and Objects
Service Components
Objects
WCF and SOA
However:
• Just because you have exposed an interface over a Web service
protocol stack does not mean that you have created part of an SOA
• SOA helps you design services and WCF enables you to implement
these services
WCF in an SOA Context
Example:
Language level:
• Objects for customers persisted into a database
• Business rules (some may be in stored procedures)
• Business interface to embody small amounts of business process
• Standard .NET Framework objects
Service level:
• Similar business facades but with potentially different data types
that are more service friendly
• These are, and use, WCF-aware data types
Lesson: Overview of WCF Architecture
• Service-Oriented Development with WCF
• Structure of a Service
Use a service:
• Contact the service to access one part of that functionality
Channel Channel
Channel Channel
Channel Channel Endpoints
Transport Transport
channel channel
The ABC of Endpoints
Address
Binding
Example: BasicHttpBinding
Contract
What the service can do for you
Example: [OperationContract]
int Add(int num1, int num2);
Structure of a Service
.NET Classes
and Interface
Service
Service
Service Contracts for Host
Domain Functionality
or Metadata Exchange
A Unified Programming Model
Windows
Communication
Foundation
• Web services
Older Web services such as ASP.NET .ASMX files
Other Web service stacks that support different WS-*
protocols
Plain Old XML services (POX)
Internal protocols
MSMQ (there are several specific bindings)
.NET Remoting
COM+
Lesson: Using a Language-Level Interface As a
Service Contract
• Example of a Simple Contract
using System;
Principal
using System.ServiceModel;
namespace
namespace ConnectedWCF for WCF
{
[ServiceContract(Namespace="http://myuri.org/Simple") ]
public interface IBank
{
[OperationContract]
decimal GetBalance(string account);
[OperationContract]
void Withdraw(string account, decimal amount);
[OperationContract]
void Deposit(string account, decimal amount);
}
}
Attributes control exposure of types and methods
The ServiceContract Attribute
The ServiceContract attribute:
• Can be used on interfaces or classes
• Is identified by tools and environments designed for WCF
Service contracts:
• Support services
• Are analogous to interfaces on a polymorphic object – caller may
not care about other contracts
• Are only visible to clients if exported on an endpoint
• Contains one or more operations
OperationContract
Data and Messages
• Parameters and return values must be marshaled between
client and server
• CLR types are mapped to XML Infoset by serialization
Generate
Service
Proxy
ServiceModel Metadata
Utility Tool (Svcutil.exe)
Implements Proxy
generates metadata
Artifacts
and artifacts
Lesson: Implementing a Simple WCF Service in
Visual Studio 2008
• Defining the Service Contract and Service Class
using BankServiceClient.BankServiceReference;
...
IBank proxy = new BankClient("WSHttpBinding_IBank");
...
double balance = proxy.GetBalance(1234);
Demonstration: Calling the Simple Bank Service
In this demonstration, you will see how to invoke
operations on a simple WCF service by using the facilities of
Visual Studio 2008
Lab: Creating a Simple Service
• Exercise 1: Creating a Simple WCF Service
Logon information
Password Pa$$w0rd
• Best Practices
• Tools