Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Understanding Windows Communication Foundation Nick Page Application Architect Microsoft Ltd.

Similar presentations


Presentation on theme: "1 Understanding Windows Communication Foundation Nick Page Application Architect Microsoft Ltd."— Presentation transcript:

1 1 Understanding Windows Communication Foundation Nick Page Nick.Page@microsoft.com Nick.Page@microsoft.com Application Architect Microsoft Ltd

2 2 Agenda Why another way to do A to B Basic Principles of WCF Creating a Service

3 Windows Communication Foundation 1996 ISV1996 ISV - Applications are Islands - Internal only - ISAM. Client/Server just becoming popular - Interop using flat files – CSV, ftp, shares - Microsoft offered simple proprietary technology-DCOM 2006 ISV2006 ISV - Applications are part of solutions - Internal and External users - Composability - Security - Scalability - “Interop” becomes core requirement

4 Windows Communication Foundation Which technology? Remoting ASMX / WSE DCOM System.Messaging Enterprise Services Microsoft Sockets RMI JAX-RPC CORBA JMS EJB J2EE Sockets

5 Interop with other platforms ASMX Attribute-BasedProgramming Enterprise Services WS-*ProtocolSupport WSE Message-OrientedProgramming System.Messaging Extensibility Location transparency.NET Remoting WCF Windows Communication Foundation Unified Programming Model

6 6 Side-by-side co-existence with existing distributed technologies Seamless communication with applications built on existing technologies Smooth upgrade of existing code to WCF Investment Protection Leveraging Existing Microsoft Investments ASMX ASMX ASMXESWSE3

7 7 using System.Web.Services; public class AccountingOperation { public string AccountName; public long Amount; } public class Accounting { [WebMethod(TransactionOption=TransactionOption.RequiresNew)] public int AddEntry(AccountingOperation debit, AccountingOperation credit) { // Add entry to internal accounting book // return id. } } using System.ServiceModel; [ServiceContract(FormatMode=ContractFormatMode.XmlSerializer)] [OperationContract] [OperationBehavior(AutoEnlistTransaction=true)] // ASMX to WCF

8 8 Basic Principles  Clients and Services  Endpoints  A, B, C  Behaviors

9 9 Client Service Clients and Services

10 10 Client Service Endpoints Endpoint

11 11 Client Service Address, Binding, Contract CBA CBA CBA A BC Address Where? Contract What? Binding How?

12 12 Client Service Behaviors CBA CBA CBA A BC B B B

13 13 Selecting… AddressBinding BehaviourContract HTTP Transport TCPTransport NamedPipe Transport MSMQ Transport Custom Transport WS-Security Protocol WS-RM Protocol WS-Coord Protocol Duplex Channel Custom Protocol http://... net.tcp://... net.pipe://... net.msmq://... xxx://... ThrottlingBehavior Metadata Behavior Error Behavior Custom Behavior Instancing Behavior Concurrency Behavior Transaction Behavior Security Behavior Request/ Response One-Way Duplex net.p2p://... PeerTransport Externally visible, per-endpoint Opaque, per-service, endpoint, or operation

14 14 Creating a Service  Define What to Expose (Contract)  Implement Contract  Define Endpoint(s)  Define How to Expose (Binding)  Define Where to Expose (Address)  Host & Run Service

15 15 C ontracts A Service is a CLR Class that Implements One or More Service Contracts [DataContract] public class OrderDetail { [DataMember] public string ItemName { get; set; } [DataMember] public Guid ItemId { get; set; } [DataMember] public double ItemPrice { get; set; } } [ServiceContract] public interface IOrderProcessingService { [OperationContract(IsOneWay = true)] void ProcessOrder(OrderDetail detail); } class OrderProcessingService : IOrderProcessingService { public void ProcessOrder(OrderDetail detail) {... } } [DataContract] public class OrderDetail { [DataMember] public string ItemName { get; set; } [DataMember] public Guid ItemId { get; set; } [DataMember] public double ItemPrice { get; set; } } [ServiceContract] public interface IOrderProcessingService { [OperationContract(IsOneWay = true)] void ProcessOrder(OrderDetail detail); } class OrderProcessingService : IOrderProcessingService { public void ProcessOrder(OrderDetail detail) {... } }

16 16 Encoding Text, Binary, MTOM, Custom Transport Selection TCP, HTTP, Named Pipes, Peer Channel, MSMQ, Custom End-to-End Security Confidentiality, Integrity, AuthN, AuthZ, Federation & Infocard X.509, Username/Password, Kerberos, SAML, XrML, Custom End-to-End Reliable Messaging Transport-Independent QoS (In-Order / Exactly-Once) Volatile and Durable Queues for Availability Transactions Shared Transactions for “Synchronous” Operations Transactional Queues for “Asynchronous” Operations B inding

17 17 A ddresses http://microsoft.com:80/OrderService/WShttps://microsoft.com:443/OrderService/BPnet.tcp://microsoft.com:808/OrderService/TCPnet.pipe://microsoft.com/OrderService/NP Scheme http, https, net.tcp, net.pipe Host Name microsoft.com Port (Optional) * 80, 443, 808 Base Path /OrderService/ Endpoint Address WS, BP, TCP, NP * - Port Does Not Apply to Named Pipes

18 18 Hosting ServiceHost allows for hosting anywhere Console applications Windows applications Windows services IIS provides an enterprise class hosting environment Edit a.svc file and point at your service HTTP transport in IIS 6.0 All transports in IIS 7.0 (Windows Activation Service)

19 19 ServiceHost Allows a WCF Service to be Hosted in Any AppDomain EXE, NT Service, WinForms, Avalon, etc. public static void Main(string[] args) { ServiceHost host = new ServiceHost( typeof(OrderProcessingService); host.BaseAddresses.Add( new Uri(“http://localhost/OrderService/”)); host.Open(); } public static void Main(string[] args) { ServiceHost host = new ServiceHost( typeof(OrderProcessingService); host.BaseAddresses.Add( new Uri(“http://localhost/OrderService/”)); host.Open(); }

20 20 Windows Communication Foundation Svctraceviewer.exeSvcconfigeditor.exe + so much more

21 21 © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

22 22 WCF Code Migration

23 23 using System.Web.Services; public class AccountingOperation { public string AccountName; public long Amount; } public class Accounting { [WebMethod(TransactionOption=TransactionOption.RequiresNew)] public int AddEntry(AccountingOperation debit, AccountingOperation credit) { // Add entry to internal accounting book // return id. } } using System.ServiceModel; [ServiceContract(FormatMode=ContractFormatMode.XmlSerializer)] [OperationContract] [OperationBehavior(AutoEnlistTransaction=true)] // ASMX to WCF

24 24 public class Accounting : ServicedComponent { public void AddCreditEntry(string creditAccount, int creditAmount) { } using System.EnterpriseServices; [ComponentAccessControl] [SecureMethod] [Transaction(TransactionOption.Required)] [SecurityRole("Manager")] using System.ServiceModel; [ServiceContract] [OperationContract] [OperationBehavior(AutoEnlistTransaction=true)] [PrincipalPermission(SecurityAction.Demand, Role="Managers")] // Enterprise Services to WCF

25 25 using Microsoft.Web.Services3; [WebService] class HelloWorld { [WebMethod] public string Hello (string text) { MessageSignature signature = (MessageSignature) RequestSoapContext.Current.Security.Elements[0]; if (!signature.SigningToken.Principal.IsInRole ("BUILTIN\Administrators")) throw new AuthorizationException("Access denied"); return String.Format("Hello, {0}", text); } } Note: Configuration entry changes are required [OperationContract] [PrincipalPermission(SecurityAction.Demand, null, "BUILTIN\Administrators")] using System.ServiceModel; [ServiceContract] // // // // // // // // WSE to WCF

26 26 class MyQService { public void ReceiveOrders() { MessageQueue Queue = new MessageQueue(@".\private$\Books"); XmlMessageFormatter formatter = new XmlMessageFormatter( new Type[] { typeof(System.Data.DataSet)}); Queue.Formatter = formatter; System.Messaging.Message msg = null; while((msg= Queue.Receive()) != null) { DataSet booklist = (DataSet) msg.Body; ProcessOrders(booklist); } } Public void ProcessOrder(DataSet BookList) {... } } using System.Messaging; using System.ServiceModel; [ServiceContract] [OperationContract(IsOneWay = true)] // // // // // // // // // // // // // System.Messaging to WCF

27 27 using System.Runtime.Remoting; [Serializable] public class AccountingOperation { public string AccountName; public long Amount; } public class Accounting { public int AddEntry(AccountingOperation debit, AccountingOperation credit) { // Add entry to internal accounting book // return id. } } using System.ServiceModel; [ServiceContract] [OperationContract] : MarshalByRefObject //.NET Remoting to WCF


Download ppt "1 Understanding Windows Communication Foundation Nick Page Application Architect Microsoft Ltd."

Similar presentations


Ads by Google