Download presentation
Presentation is loading. Please wait.
2
Introduction WCF Definition WCF Architecture Implementation WCF Demo Overview
3
Introduction
4
Web Services Everywhere…
5
Web Services Components Universal Description Discovery and Integration, exampleexample Web Services Description Language Define the structure of an XML document, just like a DTD Simple Object Access Protocol
6
Client Invoking a Web Service
7
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... HTTP Communication Headers Data VerbURL
8
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... { "Age":37, "FirstName":"Eyal", "ID":"123", "LastName":"Vardi“ } Headers Data VerbURL JSON vs. SOAP
9
WCF Definition
10
Visual Studio 2008 Clarifying Version Confusion….NET Framework 3.5.NET Framework 3.0 + SP1.NET Framework 2.0 + SP1 Windows Presentation Foundation Windows Communication Foundation Windows Workflow Foundation Windows CardSpace
11
WCF designed to offer a manageable approach to: – Distributed computing. – Broad interoperability. – Direct support for service orientation. Windows Communication Foundation (WCF)
12
A unified development model Windows Communication Foundation Many confusing and complicated options RemotingCOM DCOM COM+ MSMQ WSE ASMX A Unified Programming Model
13
WCF Architecture
14
Client Service WCF dispatcher Proxy Message Encoding Transport channel Transport channel Channel Transport channel Transport channel Encoding Binding Channel Endpoints Listen for messages on one or more endpoints. Proxy object used to send messages to the service. Proxy hides communications complexity, and makes the remote service appears as local object. Matching Binding Sending a WCF Message
15
Service.NET Classes and Interface Service Host Service Contracts or Metadata Exchange mex enables communication without prior knowledge of the contract (metadata about the service). IIS / Standalone Managed Application Structure of a Service
16
Service Where to find the service Example: http://localhost:8001/MathService Where to find the service Example: http://localhost:8001/MathService Address How to communicate with the service Example: BasicHttpBinding How to communicate with the service Example: BasicHttpBinding Binding 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); Contract The ABC of Endpoints
17
Windows Forms application Windows Console application Windows service WPF application Hosting a WCF Service in a Self-Hosted Managed Application
18
Implementation
19
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. Essential Pieces of WCF
20
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 WCF Service Files
21
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); } Attributes control exposure of types and methods Example of a Simple Contract
22
<endpoint address="BankService" binding="basicHttpBinding" contract="ConnectedWCF.IBank"/> <baseAddress baseAddress="http://localhost:8080/Simple"/> <endpoint address="BankService" binding="basicHttpBinding" contract="ConnectedWCF.IBank"/> <baseAddress baseAddress="http://localhost:8080/Simple"/> Root element is system.serviceModel WCF-specific elements below this have various properties and sub elements Identifying WCF Entries in Configuration Files
23
Service Class Service Interface Service Metadata Implements Running Service Proxy Implements Service Assembly Proxy Artifacts Generate ServiceModel Metadata Utility Tool (Svcutil.exe) generates metadata and artifacts http://msdn.microsoft.com/en-us/library/aa347733(v=VS.90).aspx Contracts, Metadata, and Artifacts
24
WCF Service Host WCF Service Library Contract Implementation Configuration WCF solution Host code Separation of Concerns in a WCF Service Best Practices
25
WCF Demo
26
WCF Standard Bindings NameTransportEncodingInterop BasicHttpBindingHTTP/HTTPSTextYes NetTcpBindingTCPBinaryNo NetPeerTcpBindingP2PBinaryNo NetNamedPipeBindingIPCBinaryNo WSHttpBindingHTTP/HTTPS Text, MTOM Yes WSFederationBindingHTTP/HTTPS Yes WSDualHttpBindingHTTP/HTTPS Yes NetMsmqBindingMSMQBinaryNo NetIntegrationBindingMSMQBinaryYes
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.