Wcf

560 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
560
On SlideShare
0
From Embeds
0
Number of Embeds
42
Actions
Shares
0
Downloads
32
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • WCF combines many previous Microsoft messaging technologies together into a standard coding framework. A service is written as a logical piece of work and is then exposed using whichever method is most appropriate. This keeps the service logic and the technical transportation pieces of the service separate and reduces the complexity.
  • There are numerous ways that a message can be formatted/sent/secured, this allows you to tailor your service for the compatibility/performance you require for your solution. Because there is such a large number of choices that can be made these have been packaged into ‘standard binding’ sets for easy use. A service can support multiple sets of bindings, however each must be on a separate address. The Client must use exactly the same binding as service otherwise they will not be able to communicate properly.
  • We will talk about just the first three in this presentation. Message Contracts help in specifying the actual SOAP message and isn’t used as much as the other 3
  • To expose a class and methods as a service you need to decorate them with metadata, this allows .NET to map this the CLR to WCF. A single Class can implement multiple ServiceContracts it just needs to implement multiple Interfaces. The methods exposed with [ OperationContract] can only use primitive or data contracts as parameters.
  • To expose a class and methods as a service you need to decorate them with metadata, this allows .NET to map this the CLR to WCF. A single Class can implement multiple ServiceContracts it just needs to implement multiple Interfaces. The methods exposed with [ OperationContract] can only use primitive or data contracts as parameters.
  • Self hosting can be done in any .NET application: WPF, Winforms, WF, console, windows service, etc. An advantage of hosting on IIS or WAS over self hosting is that the process needs to be running constantly with a self hosted solution, whereas one hosted on IIS or WAS isn’t launched until there is a client request.
  • Wcf

    1. 1. ARIANA
    2. 2.  Introduction to WCF  What is it? Why use it?  Architecture  Fundamentals and the ABCs of WCF  Hosting  Tooling Support  Handling faults
    3. 3.  Stands for Windows Communication Foundation  One of the 4 pillars of .NET 3.0  Microsoft’s unified programming model (the service model) for building Service-Oriented Applications
    4. 4.  Service Small program interacted by well defines message exchanges Agile, Reliable, Stable, Interoperable, Secure  Four Tenets Boundaries are Explicit Services are Autonomous Services share schema and contract, not class Service compatibility is based upon policy
    5. 5.  WCF provides: an SDK for creating SOA a runtime for running Services on Windows  Services send and receive messages  All messages are SOAP messages  WCF takes care of all the plumbing
    6. 6.  Interoperable and Standards based  Supports WS-* protocols  Unified Programming Model  Unifies previous models like .NET Remoting, ASMX web services, COM+ etc  Productive Programming Model  Declarative  Imperative  Configuration based
    7. 7.  Simplicity  Flexibility  Maintainability  Power
    8. 8. Every service has  Address Where the service is  Binding How to talk to the service  Contract What the service can do
    9. 9.  Combination of transport, server name, port & path  Transport is determined by the binding  Examples http://localhost:8001 net.tcp://localhost:8002/MyService net.pipe://localhost/MyPipe net.msmq://localhost/private/MyService net.msmq://localhost/MyService
    10. 10.  Transport  HTTP  TCP  MSMQ  Message formats and encoding  Plain text  Binary  Message Transmission Optimization Mechanism (MTOM)  Communication security  No security  Transport security  Message security  Authenticating and authorizing callers
    11. 11.  BasicHttpBinding  WSHttpBinding  WS2007HttpBinding  WSDualHttpBinding  WSFederationHttp Binding  WS2007FederationHttpBind ing  NetTcpBinding  NetNamedPipeBinding  NetMsmqBinding  NetPeerTcpBinding  WebHttpBinding  MsmqIntegrationBinding
    12. 12.  Service contracts Defines operations, communications and behaviours.  Data contracts Defines data entities and parameter types.  Fault contracts Defines error types  Message contracts Defines message formats
    13. 13.  [ServiceContract] – Defines a ‘set’ of operations  [OperationContract] – Defines a single method [ServiceContract] public interface IService { [OperationContract] string GetData(int value); } public class ConcreteService : IService { public string GetData(int value) { ... } public string OtherMethod() { ... } } [ServiceContract] public interface IService { [OperationContract] string GetData(int value); } public class ConcreteService : IService { public string GetData(int value) { ... } public string OtherMethod() { ... } }
    14. 14.  [DataContract] – Specifies type as a data contract  [DataMember] – Members that are part of contract [DataContract] public class CustomType { [DataMember] public bool MyFlag { get; set; } [DataMember] public string MyString { get; set; } } [DataContract] public class CustomType { [DataMember] public bool MyFlag { get; set; } [DataMember] public string MyString { get; set; } }
    15. 15.  DataContract: created specifically for WCF to serialize types  Attribute contains Name and Namespace properties  DataMember is needed to specify which properties/fields will form part of the contract  Contains EmitDefaultValue, IsRequired, Name, Order properties
    16. 16.  Service can also expose endpoint for Metadata Exchange (MEX)  It provides a mechanism for clients to find out about:  Address of other end points  Bindings that are used  Contracts used – Service, Operation, Data, etc
    17. 17.  IIS  HTTP only  WAS (Windows Activation Service)  Can use any transport  Vista and Windows Server 2008 only  Self hosting  Can use any transport  Can be hosted within Console, WinForms, etc Applications
    18. 18.  Visual Studio  Separate projects for WCF  “Add Service reference” menu  WCF Configuration Editor  WCF Service Host  WCF Test Tool  SvcUtil – To generate proxies  SvcTraceViewer – To view logs
    19. 19.  Three main kinds of Exceptions can occur:  Communication errors  Unexpected error on the service  Errors thrown by the service on purpose  .NET Exceptions are technology specific  All Exceptions come across the wire as SOAP Faults
    20. 20.  In WCF, SOAP faults are passed in as FaultException objects  Rather than throwing Exceptions, services should throw FaultExceptions  Or better still FaultException<T>  Throwing FaultExceptions will not fault the proxy and the channel
    21. 21.  Specifies what kind of Exceptions, an operation can throw [ServiceContract] public interface IEmployeeService { [OperationContract] [FaultContract(typeof(ValidationException))] public void AddEmployee(Employee e); } [ServiceContract] public interface IEmployeeService { [OperationContract] [FaultContract(typeof(ValidationException))] public void AddEmployee(Employee e); }
    22. 22.  Its made of a lot of different components, so you can create new components for security, transport, authentication.  In WCF, there is no need to make much change in code for implementing the security model and changing the binding. Small changes in the configuration will make your requirements.  Its faster than ASMX  Its Interoperability, for java, and more.  WCF is interoperable with other services when compared to .Net Remoting, where the client and service have to be .Net  WCF services provide better reliability and security in compared to ASMX web services.
    23. 23.  WCF is Microsoft's implementation of SOA and hence its APIs are solely controlled by MS which makes interoperability a bit difficult.  To deploy WCF apps, need more underlying hardware resources on the platform on which the WCF applications will be running, since there is an additional layer of abstraction to deal with.
    24. 24.  WCF provides a runtime for creating Service Oriented Apps  Provides a productive programming model. Takes care of:  Messaging and Exchange formats  All Plumbing: Transaction, Reliability, Security, etc  Supports Declarative (via attributes), Imperative (via code) and Configuration based (via config files) programming model  ABCs of Endpoints  Address: Where to go?  Binding: How to get there?  Contract: What to do?  Hosting  IIS, WAS, Self-hosting

    ×