1 / 29

WCF 101

WCF 101. Barry Dorrans http://idunno.org. About the Speaker (the ego slide). MVP – Visual Tools, Security barryd@idunno.org. Agenda What is WCF? The ABCs of WCF Defining a contract Hosting the service Handling Errors Logging. What is WCF?. Indigo

annot
Télécharger la présentation

WCF 101

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. WCF 101 Barry Dorrans http://idunno.org

  2. About the Speaker(the ego slide) MVP – Visual Tools, Security barryd@idunno.org

  3. Agenda What is WCF? The ABCs of WCF Defining a contract Hosting the service Handling Errors Logging

  4. What is WCF? Indigo Replaces Web Services, WSE & Remoting Interoperability

  5. The ABCs of WCF Address Binding Contract

  6. Client Server Messaging Layer Endpoint Service Model Address Binding Channel Behaviour Behaviour Contract Binding Binding Channel Behaviour Behaviour Factory Listener Channel Address Address Channel *

  7. Address scheme:// <machineName>[:port]/path http://localhost:8080/Account/ net.tcp://localhost:8080/Account

  8. Binding How you communicate with a service A service may have multiple bindings Defines the shape; security etc.

  9. Contract The external interface Contracts for service, data and message

  10. The ABCs Address = WHERE Binding = HOW Contract = WHAT

  11. Service Contracts [ServiceContract()] public interface IMyService { [OperationContract] string MyOperation1(string myValue); [OperationContract] string MyOperation2(MyDataContract value); }

  12. Data Contracts [DataContract] public class MyDataContract { string _stuff; [DataMember] public string Stuff { get { return _stuff; } set { stuff = value; } } }

  13. Creating our first WCF service

  14. So what have we learned? VS2008 gives us a test harness Service behaviour in config Barry can’t type under pressure.

  15. Why data contracts?

  16. Why data contracts? Message body or Message Header Control over the order of members Required versus optional parameters

  17. Version Tolerance

  18. So what have we learned? We need data contracts Why? – Version Tolerance WCF exposes nothing by default This is the opposite of XML Serialization

  19. Hosting the service

  20. So what have we learned? We can host in IIS or a .net program So we can use WCF for inter-process or inter-program communication

  21. Hosting in a program Create a new ServiceHost and Open using (ServiceHost host = new ServiceHost(typeof(MyService))) { host.Open(); ..... }

  22. Hosting in IIS Add a .svc file <%@ServiceHost Service="Namespace.ServiceType" %> <%@Assembly Name="AssemblyName" %>

  23. Replacing ASMX Double Decorate Contracts Watch the action & message names Remap ASMX to WCF Only use basicHttpBinding

  24. Gotcha! Registering addresses netsh http add urlaclurl=http://+:8080/echoService user=BUILTIN\Users

  25. Getting service information foreach (ServiceEndpoint endpoint in myServiceHost.Description.Endpoints) { Console.WriteLine("Endpoint - address: {0}", endpoint.Address); Console.WriteLine("- binding name:\t\t{0}", endpoint.Binding.Name); Console.WriteLine("- contract name:\t\t{0}", endpoint.Contract.Name); }

  26. Exceptions and errors.

  27. So what have we learned? Raw exceptions are not helpful Inner exceptions are still not good Contracted faults are the way to go

  28. Logging

  29. Questions?

More Related