260 likes | 453 Views
Windows Communications Foundation. Overview. Introduction WCF Definition WCF Architecture Implementation WCF Demo. Introduction. Web Services Everywhere…. Web Services Components. Universal Description Discovery and Integration, example. Web Services Description Language.
E N D
Windows Communications Foundation
Overview • Introduction • WCF Definition • WCF Architecture • Implementation • WCF Demo
Web Services Components Universal Description Discovery and Integration, example Web Services Description Language Define the structure of an XML document, just like a DTD Simple Object Access Protocol
HTTP Communication URL Verb Data POST SimpleService.asmx/EchoString HTTP/1.1 Host: localhost:1489 User-Agent: Mozilla/5.0 Accept: text/html Content-Type: application/json; Content-Length: 27 ... XML, JSON, SOAP, AtomPub ... Headers
JSON vs. SOAP URL Verb POST SimpleService.asmx/EchoString HTTP/1.1 Host: localhost:1489 User-Agent: Mozilla/5.0 Accept: text/html,application/xhtml+xml Content-Type: application/json; Content-Length: 27 ... Headers Data { "Age":37, "FirstName":"Eyal", "ID":"123", "LastName":"Vardi“ } <Envelope> <Header> <!–- Headers --> <!-- Protocol's & Polices --> </Header> <Body> <!– XML Data --> </Body> </Envelope>
Clarifying Version Confusion… .NET Framework 3.5 .NET Framework 3.0 + SP1 Visual Studio 2008 .NET Framework 2.0 + SP1 Windows Presentation Foundation Windows Communication Foundation Windows Workflow Foundation Windows CardSpace
Windows Communication Foundation (WCF) • WCF designed to offer a manageable approach to: • Distributed computing. • Broad interoperability. • Direct support for service orientation. • WCF simplifies development of connected applications through a new service-oriented programming model.
A Unified Programming Model Many confusing and complicated options Remoting COM DCOM WSE MSMQ ASMX COM+ WindowsCommunicationFoundation A unified development model
Sending a WCF Message Channel Channel Channel Channel Endpoints Channel Channel Binding Message WCF dispatcher Client Service Proxy Proxy object used to send messages to the service. Proxy hides communications complexity, and makes the remote service appears as local object. Matching Binding Listen for messages on one or more endpoints. Encoding Encoding Transport channel Transport channel
Structure of a Service .NET Classes and Interface Service IIS / Standalone Managed Application Service Contracts or Metadata Exchange Service Host mex enables communication without prior knowledge of the contract (metadata about the service).
Address The ABC of Endpoints Binding Where to find the service Example: http://localhost:8001/MathService Contract How to communicate with the service Example: BasicHttpBinding What the service can do for you Example: [OperationContract] int Add(int num1, int num2); A Service B C
Hosting a WCF Service in a Self-Hosted Managed Application Windows Forms application Windows service Windows Console application WPF application
Essential Pieces of WCF • Contracts for services, data, and messages • A contract is simply an interface declaration • Service, Data, and Message definitions • Class implementations • Configurations defined programmatically or declaratively • config files. • A host process (can be self hosted) • IIS, Windows Executable, Windows Service, or WAS • .Net Framework (3.5) Classes provide support for all of the above.
WCF Service Files • IService.cs • Interface(s) that define a service, data, or message contract • Service.cs • Implement the service’s functionality • Service.svc • Markup file (with one line) used for services hosted in IIS • Configuration files that declare service attributes, endpoints, and policy • App.config (self hosted) contains service model markup • Web.config (hosted in IIS) has web server policy markup plus service model markup, as in App.config
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); } Attributes control exposure of types and methods
Identifying WCF Entries in Configuration Files • Root element is system.serviceModel • WCF-specific elements below this have various properties and sub elements <system.serviceModel> <services> <service name="ConnectedWCF.BankService"> <endpoint address="BankService" binding="basicHttpBinding" contract="ConnectedWCF.IBank"/> <host> <baseAddresses> <baseAddress baseAddress="http://localhost:8080/Simple"/> </baseAddresses> </host> </service> </services> </system.serviceModel>
Contracts, Metadata, and Artifacts Running Service Implements ServiceAssembly ServiceClass Service Metadata Generate Generate Service Interface Generate Service Proxy ServiceModel Metadata Utility Tool (Svcutil.exe) generates metadataand artifacts ProxyArtifacts Implements http://msdn.microsoft.com/en-us/library/aa347733(v=VS.90).aspx
Separation of Concerns in a WCF Service WCF Service Library Contract Implementation WCF solution WCF Service Host Configuration Best Practices Host code