SOA and WCF (Windows Communication Foundation) basics

  • 3,222 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
3,222
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Distributed Applications,Web Services, and WCF Yaniv Pessach
  • 2. About the Presenter As a key member of Microsoft Web Services design team, he was responsible for several of the key patents implemented in the .NET WCF implementation, and is a named contributor to two of the WS-* standards (WS-Discovery and WS-Soap-over-UDP)
  • 3. Introduction • Web Services − What are they − Why/When to use − How to design for (SOA) − Technologies (legacy) − WCF
  • 4. Take-away• Web Services enable a new way of building distributed applications in a loosely coupled, independent way• Web Services are based on layers of standards and building blocks which are supported by modern tools• Service Oriented Architecture starts by thinking of the interfaces first; useful enterprise patterns exist• .NET 3.0 introduced Windows Communication Foundation which obsoletes previous communication frameworks• WCF exposes easy access to most WS layers• WCF is based on a Contract, Binding, and Address
  • 5. Agenda• Web Services Concepts − Introducing the web services concepts − Case study - car dealership – discussion• Building Web Services − Existing building blocks and standards − Principles of SOA − The car dealership architecture – discussion• Web Services Technology − Legacy Technologies − .NET 3.0 / WCF [20] concepts • MiniSample [10] The WCF car dealer
  • 6. Web Services Properties• Contract defines interaction• Loosely Coupled, avoid dependencies• True Platform Independence• Build, maintain, version, deploy separately• External, Internal, Intra-application
  • 7. Message Exchange Patterns• Synchronous, Asynchronous, Fire & forget• Uncorrelated/Correlated by transport/Msg• Request/Response (RPC style) vs. Publish / Subscribe vs. One-Way• Multicast• Queuing helps logical fire & forget
  • 8. The Fjord Dealership• Dealer buys cars, sells cars• Deals with other dealers (get cars on lot)• Verify VIN• Approve Loan• Accept Credit-cards• Etc.
  • 9. Discussion: Identify WS• In groups, discuss the needed web services − External − Internal − Reliability, performance, data requirements?
  • 10. Web Services Layers• Base standards• Logical Protocol• Semantic Protocols ws- Orch transact estra tion Ws-policy WSDL ws-security ws-discovery XML SOAP SOAP ws-addr OVER *
  • 11. Standards• Transports • WS-Reliability• WSDL • WS-transaction• WS-Addressing • WS-Orchestration• Profiles and WS-I • UDDI and WS-• WS-Security Discovery
  • 12. WS-Addressing• How do we identify a service? EPR• URI or URI + RefProp• <wsa:EndpointReference …> <wsa:Address>http://www.b.com/1</wsa:Address> <wsa:ReferenceProperties> <blah:CustomerKey>123456789</fblah:CustomerKey> </wsa:ReferenceProperties> </wsa:EndpointReference>• MessageID, RelatesTo, Action
  • 13. [WS-]SOAP Over TCP• Wire format• HTTP no longer transport of choice• Performance• No transport level security (https)• Also – Soap Over UDP• Connection sharing [non-standard]
  • 14. WS-Security• HTTPS only provides transport level security – consider the intermediary• Integrity & confidentiality• Using SOAP header• Username, X.509, Kerberos, XML Sig• Performance vs. TLS ?
  • 15. WS-Discovery vs. UDDI• Using discovery − .NET vs. java ‘locator’ thinking• UDDI successes and failures − Trust, Service Definition• WS-Discovery − limited scope − Present and Future
  • 16. SOA• Contract• Encapsulate• Distinct Service• Services exchange data, not share behavior
  • 17. Loose Coupling• Sacrifices interface optimization• Achieve flexible interoperability• .. And ease of change• .. And does not come naturally
  • 18. Loose and Tight Coupling Tightly Loosely Msg Style RPC Doc Msg Path Hardcode Route Technology Homogenous Heterogeneous Binding Early, fixed Late Interaction Synchronous Asynchronous Model Reuse Broad applicability Adaptation Recoding Transformation Behavior Anticipated Unexpected* Adapted from ‘loosely coupled’ by Doug Kaye
  • 19. SOA Patterns• Self Service Client• Service Locator (mostly Javathink)• Broker, Router Variation, XML firewall• Serial and Parallel process pattern• Cached object pattern• Queue and MessageBus• Pub/Sub and distributed observer pattern
  • 20. SOA Patterns - Implementation• The Message is the Media• Contract First/Contract Second• Fowlerisms − Service Layer − Transform View − Remote Façade − Data Transfer Object − Service Stub [testing]
  • 21. Architect Fjord WS• Major Services• Building Blocks• Discussion!
  • 22. Legacy Technologies• Microsoft − RPC − DCOM − .NET 1.1 Remoting − .NET 1.1 WS• Issues − Interoperability − Specific limitations
  • 23. WCF Presented• Released in .NET 3.0• Diverse Stack• Address / Binding / Contract• Unique Features − Existing building blocks − Ease of implementation, deployment, maint − XML compression, performance
  • 24. ABC• Address, Binding, Contract − EPR − System bindings, parameters, custom, and custom channels − Interface/class
  • 25. Topics• Hosting• Channels and extensibility − Existing channels, transports, reliability, security• Profiles• Configuration
  • 26. Code: Contract[ServiceContract()] public interface ISellCar{ [OperationContract] double price(int vin); [OperationContract (IsOneWay=true)] Void notifyInterest(int vin);}
  • 27. Code: Client• Svcutil.exe http://...?wsdlusing (CarProxy proxy = new CarProxy()){ double result = proxy.price(617894332);}
  • 28. Code: Server• Impl: public class CarService: ISellCar {….}• Hosted: something.svc<@Service language=c# class=“….CarService“ %>• SelfHost: using (ServiceHost host = new ServiceHost(typeof(CarService), new Uri("http://..."))) { host.Open(); Thread.Sleep(1000000); host.Close(); }
  • 29. Config: Server [1]<configuration …. > <system.serviceModel> <services> <service behaviorConfiguration=“CarServiceBehavior" type=…. > <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1" contract=“….ISellCar" /> </service> </services>
  • 30. Config: Server [2]<configurationName=“CarServiceBehavior" returnUnknownExceptionsAsFaults="True"> </behavior> </behaviors><bindings> <wsHttpBinding> <binding configurationName="Binding1" /> </wsHttpBinding> </bindings> </system.serviceModel></configuration>
  • 31. Fjord With WCF• Construct pseudo/code• Discussion!
  • 32. Take-away and SummaryUse Web Services for applications, componentsUse Standards (WS-*) and building blocksArchitect using SOA patterns (routers, locators…)Use .NET 3.0/WCF as communication layerDefine the Contract; configure Binding, and AddressAdd on transports, reliability, security
  • 33. More Information• http://www.yanivpessach.com/soa_read more.txt• Contact me – yaniv@yanivpessach.com
  • 34. Backup slides
  • 35. Web Services Defined• Interoperable machine-to-machine interaction• Using SOAP and XML (some use REST)• Service and Contract• Message• SOA (service oriented architecture)
  • 36. Sending Out An S.O.A• The Need for SOA• Real world problems• Integration Nightmares• Increasing Complexity
  • 37. SOAP Sample<soap:Envelopemlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <getProductDetailsxmlns=…> <productID>827635</productID> </getProductDetails> </soap:Body></soap:Envelope>
  • 38. WS Layered Usage• External − E.g. process credit card transaction• Internal (‘inside the firewall’) − EAI e.g. accounting to helpdesk apps• Intra-application − Modular design, flexibility, common blocks
  • 39. Benefits Revisited• Built separately − different teams, timelines, platforms − enable focused teams − minimize accidental dependencies• Deployed separately − Performance, troubleshooting, versioning
  • 40. Web Services Properties• Contract defines interaction• Loosely Coupled
  • 41. Standards – Time is right* Source: Computer Networks Fourth Edition , Andrew Tanenbaum
  • 42. Standards – discuss specifics• Important• Tool support• Too many to choose from
  • 43. WS-Transaction• Long lived transaction• Problems of 2-phase commit• Based on roll-back• Flexible
  • 44. WS-Orchestration• Upper level integration• Relies on lower levels• Stabilizing• Think of it as BizTalk
  • 45. More WFC building blocks• Transactions• Behaviors − Lifetime
  • 46. Code: Channel Programmingencoder = new TextMessageEncodingBindingElement();transport = new TcpTransportBindingElement();binding = new CustomBinding(encoder, transport);IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>(); factory.Open();address = new EndpointAddress("net.tcp://192.168.0.2:5555/");IRequestChannel channel = factory.CreateChannel(address); channel.Open();request = Message.CreateMessage(factory.MessageVersion, "hello");reply = channel.Request(request);Console.Out.WriteLine(reply.Headers.Action);reply.Close(); channel.Close(); factory.Close(); } }
  • 47. Code: ReliabilityBindingElementCollection bindingElements = new BindingElementCollection(); ReliableSessionBindingElement session = new ReliableSessionBindingElement(); session.Ordered = true; bindingElements.Add(session); bindingElements.Add(new CompositeDuplexBindingElement()); bindingElements.Add(new UdpTransportBindingElement()); Binding playerInfoBinding = new CustomBinding(bindingElements);
  • 48. Code: ReliabilityBindingElementCollection bindingElements = new BindingElementCollection(); ReliableSessionBindingElement session = new ReliableSessionBindingElement(); session.Ordered = true; bindingElements.Add(session); bindingElements.Add(new CompositeDuplexBindingElement()); bindingElements.Add(new UdpTransportBindingElement()); Binding playerInfoBinding = new CustomBinding(bindingElements);Uri playerInfoAddress = new Uri( "soap.udp://localhost:16000/");using(ServiceHost service = new ServiceHost(typeof(playerInfoService))) { service.AddServiceEndpoint(typeof(IUpdatePlayerInfoContract), playerInfoBinding, playerInfoAddress); service.Open();... // more service code here }
  • 49. Code: Callback (and duplex)interface IMyContractCallback { [OperationContract] void OnCallback(); }[ServiceContract(CallbackContract = typeof(IMyContractCallback))]interface IMyContract { [OperationContract] void DoSomething(); }public sealed class InstanceContext : CommunicationObject, ... { public InstanceContext(object implementation); ... // More members }class MyCallback : IMyContractCallback { public void OnCallback() {...} } IMyContractCallback callback = new MyCallback(); InstanceContext context = new InstanceContext(callback);IMyContractCallback callback = new MyCallback(); InstanceContext context = new InstanceContext(callback); MyContractClient proxy = new MyContractClient(context); proxy.DoSomething();