Download - 6461A_01
![Page 1: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/1.jpg)
Visual Studio® 2008: Windows®
Communication Foundation
![Page 2: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/2.jpg)
Module 1: Getting Started with Windows Communication Foundation
• Designing an Application to Be Part of a Service Oriented Architecture (SOA)
• Overview of WCF Architecture
• Using a Language-Level Interface As a Service Contract
• Implementing a Simple WCF Service in Visual Studio 2008
• Consuming a Simple WCF Service in Visual Studio 2008
![Page 3: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/3.jpg)
Lesson: Designing an Application to Be Part of a Service Oriented Architecture (SOA)
• Benefits of Service Oriented Architecture
• Designing an SOA Application
• Services, Components, and Objects
• WCF and SOA
• WCF in an SOA Context
![Page 4: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/4.jpg)
Primary objective:
• Deliver more business benefit faster
• Independent services act as building blocks for new or
improved business processes
• 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
• Success depends more on business practice than technology
• SOA enables you to build services much faster once the
business has made its mind up
Benefits of Service Oriented Architecture
![Page 5: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/5.jpg)
Designing an SOA Application
Get commitment for the effort required
1
Gather the services
2
Group related business functions together
3
![Page 6: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/6.jpg)
Services, Components, and Objects
ComponentsService
Objects
![Page 7: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/7.jpg)
WCF and SOA
WCF supports SOA:
However:
• Developers do not have to learn WSDL
• Functionality is handled by the runtime
• Tools to enable easy creation and consumption of services
• 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
![Page 8: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/8.jpg)
WCF in an SOA Context
Example:
Language level:
Service level:
• Customer management service application
• 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
• Similar business facades but with potentially different data types that are more service friendly
• These are, and use, WCF-aware data types
![Page 9: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/9.jpg)
Lesson: Overview of WCF Architecture
• Service-Oriented Development with WCF
• Sending a WCF Message
• The ABC of Endpoints
• Structure of a Service
• A Unified Programming Model
• Communicating with Non-WCF Services
![Page 10: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/10.jpg)
Service-Oriented Development with WCF
Create a service:
• Over a network protocol
Use a service:
• Contact the service to access one part of that functionality
• Clients and services communicate by passing messages
• Aimed at clients and services that do not share the same address space
• Service-oriented architecture is a concept related to the style of the application and granularity of the services
• Not limited to one particular set of protocols
![Page 11: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/11.jpg)
Sending a WCF Message
Client ServiceWCF
dispatcherProxy
Message EncodingEncoding
Transportchannel
Transportchannel
ChannelChannelChannelChannel
ChannelChannel
Transportchannel
Transportchannel
EncodingEncodingBindingBinding
ChannelChannelChannelChannel
ChannelChannel EndpointsEndpoints
![Page 12: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/12.jpg)
The ABC of Endpoints
Service
Where to find the service
Example: http://localhost:8001/MathService
Where to find the service
Example: http://localhost:8001/MathService
AddressAddress
How to communicate with the service
Example: BasicHttpBinding
How to communicate with the service
Example: BasicHttpBinding
BindingBinding
What the service can do for you
Example: [OperationContract]int Add(int num1, int num2);
What the service can do for you
Example: [OperationContract]int Add(int num1, int num2);
ContractContract
![Page 13: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/13.jpg)
Structure of a Service
Service
.NET Classesand Interface
ServiceHostService Contracts for
Domain Functionalityor Metadata Exchange
![Page 14: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/14.jpg)
A Unified Programming Model
A unified development model
WindowsCommunication
Foundation
Many confusing and complicated options
Remoting COMDCOM
COM+MSMQ
WSEASMX
![Page 15: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/15.jpg)
Communicating With Non-WCF Services
•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+
![Page 16: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/16.jpg)
Lesson: Using a Language-Level Interface As a Service Contract
• Example of a Simple Contract
• The ServiceContract Attribute
• The OperationContract Attribute
• Data and Messages
• Contracts, Metadata, and Artifacts
![Page 17: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/17.jpg)
Example of a Simple Contract
using System;using System.ServiceModel;
namespace ConnectedWCF{ [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); }}
using System;using System.ServiceModel;
namespace ConnectedWCF{ [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); }}
Principal namespace for WCF
Attributes control exposure of types and methods
![Page 18: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/18.jpg)
The ServiceContract Attribute
Service contracts:
The ServiceContract attribute:
Namespace serves to disambiguate types and operations in service metadata:
• Can be used on interfaces or classes
• Is identified by tools and environments designed for WCF
• 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
• Defaults to http://tempuri.org
• Not to be confused with language-level namespace
![Page 19: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/19.jpg)
The OperationContract Attribute
• Attribute can be used on methods but not other class elements such as properties or indexers
• Identified by tools and environments designed for WCF
• Methods are only visible in service contract if marked with
OperationContract
![Page 20: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/20.jpg)
Data and Messages
• Parameters and return values must be marshaled between client and server
• CLR types are mapped to XML Infoset by serialization
• WCF enables you to define custom serialization
• Serialized data is packed into the message
• Contents and structure of message must be understood by client or service at the other end
• Data and message contracts provide control overthese areas
![Page 21: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/21.jpg)
Contracts, Metadata, and Artifacts
ServiceClass
ServiceInterface
ServiceMetadata
Implements
RunningService
ServiceProxy
Implements
ServiceAssembly
ProxyArtifacts
Generate
Generate
Generate
Generate
Generate
Generate
ServiceModel Metadata Utility Tool (Svcutil.exe) generates metadataand artifacts
ServiceModel Metadata Utility Tool (Svcutil.exe) generates metadataand artifacts
![Page 22: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/22.jpg)
Lesson: Implementing a Simple WCF Service in Visual Studio 2008
• Defining the Service Contract and Service Class
• Hosting the Service
• Configuring the Service
• Demonstration: Creating a Simple Bank Service
![Page 23: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/23.jpg)
Defining the Service Contract and Service Class
![Page 24: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/24.jpg)
Hosting the Service
![Page 25: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/25.jpg)
Configuring the Service
![Page 26: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/26.jpg)
Demonstration: Creating a Simple Bank Service
In this demonstration, you will see how to:
• Create a simple WCF service in Visual Studio 2008
• Host the service in IIS by using the facilities of Visual Studio 2008
![Page 27: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/27.jpg)
Lesson: Consuming a Simple WCF Service in Visual Studio 2008
• Importing the Metadata
• Calling the Service by Using the Proxy
• Demonstration: Calling the Simple Bank Service
![Page 28: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/28.jpg)
Importing the Metadata
![Page 29: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/29.jpg)
Calling the Service by Using the Proxy
Metadata import generates client-side classes that represents the service and service contract:
• <ServiceName> Client is the service proxy type
• <ServiceContractName> is the contract representation type
Client-side class created in the current project’s namespace when you add the service reference
using BankServiceClient.BankServiceReference;...IBank proxy = new BankClient("WSHttpBinding_IBank");...double balance = proxy.GetBalance(1234);
![Page 30: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/30.jpg)
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
![Page 31: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/31.jpg)
Lab: Creating a Simple Service
• Exercise 1: Creating a Simple WCF Service
• Exercise 2: Calling the Simple WCF Service
Logon information
Virtual machine 6461A-LON-DEV-01
User name Student
Password Pa$$w0rd
Estimated time: 60 minutes
![Page 32: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/32.jpg)
Lab Review
• What must you do to the ClinicAdminClient application if you change the AppointmentServiceContract?
• What would be the consequences to the solution if you removed the default metadata endpoint from the AppointmentServiceIISHost project?
![Page 33: 6461A_01](https://reader033.vdocuments.us/reader033/viewer/2022051208/5464f385b4af9f94578b4748/html5/thumbnails/33.jpg)
Module Review and Takeaways
• Review Questions
• Best Practices
• Tools