Publicité
Publicité

Contenu connexe

Publicité
Publicité

Complete Architecture and Development Guide To Windows Communication Foundation (WCF)

  1. Complete Architecture and Development Guide To Windows Communication Foundation (WCF) By Abdul khan
  2. Author • Abdul Khan • IT Consultant based in Manchester, UK • Engineering Lead, Executive, Technologist, Architect • IT experience, within the private and public sectors (Retail, Banking, Digital, Insurance, M.O.D., HMRC, Aviation, Telecommunication, Housing Associations, Education, Travel, and Pharmaceutical companies). Excellent architectural and strong DevOps experience with proven-track record of delivering E2E, B2B and B2C solution on regional and global programs. • SME in specializing in providing integration, data migration, digital transformations to the cloud solutions (Azure and AWS) • Wealth of experience in global projects across EMEA, ASPAC and LATAM • Liked in profile https://www.linkedin.com/in/abdul-khan-uk/
  3. Accreditations Thank you to my good friend and colleague for reviewing, adding value, sharing their vast experience and knowledge. • Steve Lampton (IT Consultant, Cloud SME) specialising in NetOps, DevOps and SecOps
  4. Audience Main Audience • Technical Managers • Architects • Technical Leads and Developers Assumptions • Reader has some knowledge of development in .NET
  5. Content 1. What Is A Service ? 2. What Is WCF? 3. WCF Architecture 4. WCF Technologies 5. WCF Features 6. Massaging Runtime Design 7. RESTful Service 8. SOAP and REST Design 9. Durable Services 10. Defining the Durable Services 11. Contracts & Service contracts 12. Data Contracts 13. Message Contracts 14. Policies and Bindings 15. Service Runtime 16. Messaging In WCF 17. Messaging Runtime/Channel Stack 18. Message Exchange Patterns 19. Message Topologies 20. Activation and Hosting 21. Understanding WCF Runtime Service Instance 23. Routing Service (WCF 4.0) 24. Discovery Service (WCF 4.0) 25. 24. Simplified configuration (WCF 4.0) 26. Metadata Exchange 27. HTTP_GET Enabled Metadata 28. Metadata Exchange Endpoint 29. Transport Security Credential Bindings 30. Types Of Authentication 31. Transfer Security Mode 32. Transport Security Mode (None) 33. Message Security Mode (Message) 34. Mixed Transfer Security Mode (Credential) 35. Security Modes (Both) 36. Throttling 37. Streaming 38. Streaming Restrictions 39. Streaming and Binding 40. Streaming and Transport 41. Transactions 42. Transaction Protocols 43. Transaction Resources 44. Transaction Client/Server transaction mode 45. Transaction None transaction mode 46. Operations 47. Request-Reply 48. One-Way 49. Callback Service 50. What Is WCF RIA Service? 51. RIA Service Architecture 52. Problem Solved By RIA 53. Domain Services 54. WCF RIA Domain Service Architecture 55. Creating WCF Service (Step-by-Step)
  6. Complete Architecture and Development Guide To Windows Communication Foundation (WCF)
  7. 1. What Is A Service? • Service are reusable units providing business functionality that are:- • Clearly defined using standard policies • Clearly described • Autonomous • Abstraction of the underlying business logic and functionality • Functionality exposed via structed messaging scheme • Not XML centric, Not HTTP centric • JOSN, XML, SOAP, Images, steaming over TCP, HTTP, Name Pipes, MSMQ etc… • Message sent and received • Moves from client/server model to a service model • Rich communication patterns • Versioning Independency • Service Orientation provides the benefits of loosely coupled , message-oriented programming model
  8. 2. What is WCF? (1/2) • An API service the communicate between applications and services. • Provides secure, reliable and transacted messaging along with interoperability • Unifies a broad array of distributed systems capabilities in an extensible architecture • Spans transport, security systems , messaging patterns , encoding, networks topologies and hosting models • WCF combines the best off all existing Microsoft distributed computing stacks • WCF use WS-* standards to interoperability and .NET value-add for performance and integration with existing solutions
  9. 2. What is WCF? (2/2) Summary, WCF provide a unified API service that’s used in various types of communication from an application . WCF is hosted on .NET frameworks and supports distributed applications Client Framework Client - Consuming Service .NET Framework WCF Service WCF Service (.NET) MSMQ DCOM WS-* TCP/IP HTTP/HTTPS Messages-oriented communication WCF provides a unified API for various communication models
  10. 3. WCF Architecture Application Contracts Services Runtime Service Contract Data Contract Message Contract Policy and Binding Throttling Behaviour Error Behaviour Metadata Behaviour Instance Behaviour Message Inspection Transaction Behaviour Concurrency Behaviour Parameter Filtering Dispatch Behaviour Messaging WS-Security WS-Reliable Messaging Encoder: Binary/MTOM/XML HTTP channel TCP Channel Transaction Flow Channel NamedPipe Channel MSMQ Channel Activation And Hosting Windows Activation Service .exe Windows Service COM+
  11. 4. WCF Technologies WSE Web Service Enhancement ASMX Active Server Methods .NET Remoting Enterprise Service Messaging WCF Attribute Base programming Interop with Other Platform WS* Protocols Support Message Oriented Programming Extensibility Location Transparency
  12. 5. WCF Features Address Http://... Binding HTTP Transport HTTP Security Contract Http://... Behaviour Instance Behaviour Concurrency Behaviour Net.p2p://.. Net.tcp://.. Net.pipe://.. Net.msmq://.. xxx://.. Peer Transport TCP Transport Namedpipe Transport MSMQ Transport Custom Transport WS-RM Protocol WS-Coord Protocol Duplex Channel Custom Protocol One way Duplex Throttling Behaviour Metadata Behaviour Error Behaviour Custom Behaviour Transaction Behaviour Security Behaviour
  13. 6. Messaging Runtime Design Client Services Dispatcher Protocol(s) Encoder Transport Protocol(s) Encoder Transport Binding Address Contract and Behaviours
  14. 7. RESTful service • Any Service which follows this REST architecture style is called as RESTful service. It became very popular because of it behaviour, it is similar to the website i.e. we can load the server information using web URL in the browser. similarly we can also access/modify the server resource using URL in RESTful service • RESTful service will allow the client (written in different language)to access or modify the resource in the server using URL. • RESTful service uses the http protocol for its communication and it is stateless • RESTful service can transfer the data in XML,JSON,RSS,ATOM
  15. 8. SOAP and REST Design SOAP POX(plain-old XML) REST  Simple Object Application Protocol  SOAP – is a package contain message information and it will be delivered by HTTP  Developers are mainly preferred to user because of its increase interoperability  Lot of tools are available in the market to generate the clients code from WSDL  Plain raw XML message will be used for communication  Developers using POX had to write their own code for XML and HTTP for request/response message.  So most of the developers moved back to SOAP  REST defines more of a transport-specific model  In reality HTTP is the only protocol that is used in practice today for building RESTful architecture.
  16. 9. Durable Services • Durable services are WCF services that persist service state information even after service host is restarted or Client. It means that durable services have the capability to restore their own state when they are recycled. It can use data store like SQL database for maintain instance state. It is new feature in .NET 3.5 • You might think that we can also maintain session using WCF sessions, but content in the session environment is not persisted by default. If the service is shut down or client closes the proxy, data will be lost. But in case of Durable service it is still maintained. • Working: • When Durable service is created with database as data store, it will maintain all its state information in the table. • When a client make a request to the service, instance of the service is serialized, a new GUID is generated. This serialized instance xml and key will be saved in the database. We will call this GUID as instanceID. Service will send the instanceID to the client, so later it can use this id to get the instance state back. Even when client is shut down, instanceId will be saved at the client side. So when ever client opening the proxy, it can get back the previous state.
  17. 10. Defining the Durable Services • Durable service can be implemented using [DurableService()] attribute. It takes 'CanCreateInstance' and 'CompletesInstance' property to mention on which operation instance state has to be saved and destroyed. • CanCreateInstance = true: Calling this operation results in creating the serialization and inserting it into the datastore. • CompletesInstance = true: Calling this operation results in deleting the persisted instance from the datastore.
  18. 11. Contracts & Service contracts • Contracts • Contracts are the Application layers. • Service contracts • Describe about the operation that service can provide. Example, Service provided to know the temperature of the city based on the zip code, this service we call as Service contract. It will be created using Service and Operational Contract attribute.
  19. 12. Data Contracts Data contracts It describes the custom data type which is exposed to the client. This defines the data types, are passed to and from service. Data types like int, string are identified by the client because it is already mention in XML schema definition language document, but custom created class or datatype cannot be identified by the client e.g. Employee data type. By using DataContract we can make client aware that we are using Employee data type for returning or passing parameter to the method.
  20. 13. Message Contract • Message Contract - Default SOAP message format is provided by the WCF runtime for communication between Client and service. If it is not meeting your requirements then we can create our own message format. This can be achieved by using Message Contract attribute.
  21. 14. Policies and Binding • Policies and Binding - Specify conditions required to communicate with a service e.g. security requirement to communicate with service, protocol and encoding used for binding.
  22. 15. Service Runtime Service Runtime contains the behaviour's that occur during runtime of service, they are: - • Throttling Behaviour- Controls how many messages are processed. • Error Behaviour - Specifies what occurs, when internal error occurs on the service. • Metadata Behaviour - Tells how and whether metadata is available to outside world. • Instance Behaviour - Specifies how many instance of the service has to be created while running. • Transaction Behaviour - Enables the rollback of transacted operations if a failure occurs. • Dispatch Behaviour - Controls how a message is processed by the WCF Infrastructure.
  23. 16. Messaging In WCF Messaging layer is composed of channels. A channel is a component that processes a message in some way, for example, by authenticating a message. A set of channels is also known as a channel stack. Channels are the core abstraction for sending message to and receiving message from an Endpoint. Broadly we can categories channels as the following: - • Transport Channels • Handles sending and receiving message from network. Protocols like HTTP, TCP, name pipes and MSMQ. • Protocol Channels • Implements SOAP based protocol by processing and possibly modifying message. E.g. WS- Security and WS-Reliability.
  24. 17. Messaging Runtime/Channel Stack Services Dispatcher Protocol(s) Encoder Transport Binding Address Contract and Behaviours
  25. 18. Message Exchange Pattern • One-way (Datagram) • Message send and no response (fire and Forget, Datagram style delivery • Request / Reply from the receiver • Message send another message received as response (immediate reply) • Duplex • Sender and receiver can exchange multiple messages • Reply later and no backchannel (call-back-style) Sender Receiver Sender Receiver Sender Receiver
  26. 19. Message Topologies • Intermediary • Invisible to the sender, promises to not materially change the message • A receiver message trigger a send another services • Request / Reply from the receiver • Message sent, one or more replies from a receiver other than the original recipient Sender Intermediary Sender ReceiverSender Receiver Receiver
  27. 20. Activation and Hosting • Services can be hosted or executed, so that it will be available to everyone accessing from the client. WCF service can be hosted by following mechanism • IIS • Internet information Service provides number of advantages if a Service uses Http as protocol. It does not require Host code to activate the service, it automatically activates service code. • Windows Activation Service • (WAS) is the new process activation mechanism that ships with IIS 7.0. In addition to HTTP based communication, WCF can also use WAS to provide message-based activation over other protocols, such as TCP and named pipes. • Self-Hosting • WCF service can be self hosted as console application, Win Forms or WPF application with graphical UI. • Windows Service
  28. 21. Understanding WCF Runtime Service Instance • A complete picture of WCF runtime with Service Instance, Dispatcher and Channel Stack is as follows: • WCF is extensible, so we can defined our own bindings but there are different built-in bindings available in WCF, each designed to fulfill some specific needs. • basicHttpBinding • wsHttpBinding • netNamedPipeBinding • netTcpBinding • netPeerTcpBinding Dispatcher Channel Stack Protocol(s) Encoder Transport Service Instance Services Method Configuration Binding, Protocol, Encoding and Transport .NET Assembly Data Contracts, Message Contracts, Service Contracts
  29. 22. Routing service (WCF 4.0) WCF 4.0 introduced routing service between client and actual business service. This intermediated service Act as broker or gateways to the actual business services and provides features for content based routing, protocol bridging and error handling Service 1 Service 2 Service 3 Routing ServiceClient
  30. 23. Discovery service (WCF 4.0) There are certain scenario in which endpoint address of the service will be keep on changing. In that kind of scenario, client who consume this service also need to change the endpoint address dynamically to identify the service. This can be achieved using WS-Discovery protocol.
  31. 24. Simplified configuration (WCF 4.0) In WCF 4.0, a simplified configuration providing default endpoint, binding and behaviour configuration. It is not mandatory to provide endpoint while hosting service. Service will automatically create new endpoint if it does find any endpoint while hosting service. These changes make it possible to host configuration-free services.
  32. 25. Metadata Exchange • WCF provides rich infrastructure for Exporting, Publishing, retrieving and Importing the metadata. WCF uses the Metadata to describe how to interact with the service endpoint. Using the metadata, client will create the proxy class for the service using SvcUtil.exe • Exporting Service Metadata • It is the process of describing the service endpoint so that client can understand how to use the service. • Publishing Service Metadata • It is the process publishing metadata. It involves converting CLR type and binding information into WSDL or some other low level representation. • Retrieving Service Metadata • It is the process of retrieving the metadata. It uses WS-MetadataExcahge or HTTP protocol for retrieving the metadata. Importing Service Metadata - It is the process of generating the abstract representation of the service using metadata.
  33. 26. HTTP_GET Enabled Metadata • WCF use ServiceBehaviour to publish the metadata using HTTP-GET • This can be configured either administratively or Programmatically • Http and Https can expose by appending "?wsdl" to the end of the service address. For example service address is http://localhost:9090/MyService , HTTP- Get metadata address is given by http://localhost:9090/MyService?wsdl.
  34. 27. Metadata Exchange Endpoint • Exposing the metadata using HTTP-GET has a disadvantage, such that there is no guarantee that other platforms you interact will support it. There is other way of exposing the using special endpoint is called as Metadata Exchange Endpoint. You can have as many metadata exchange endpoints as you want. • Address • It is basically Uri to identify the metadata. You can specify as address in the endpoint but append with "mex" keyword. For example "http://localhost:9090/MyCalulatorService/mex" • Binding • There are four types of bindings supported for metadata exchange. They are mexHttpBinding, mexHttpsBinding, mexNamedPipesBinding, mexTcpBinding. • Contract • IMetadataExchange is the contract used for MEX endpoint. WCF service host automatically provides the implementation for this IMetadataExcahnge while hosting the service. • You can create the Metadata Exchange Endpoint either Administrative (configuration file) or programmatically.
  35. 28. Transport Security Credential Bindings Name None Windows Username Certificate BasicHttpBinding Yes(default) Yes Yes Yes NetTcpBinding Yes Yes(default) No Yes NetNamedPipeBinding No Yes(default) No No WsHttpBinding Yes Yes(default) Yes Yes WsDualHttpBinding N/A N/A N/A N/A NetMsmqHttpBinding Yes Yes(default) No Yes
  36. 29. Types of Authentication • WCF Authentication is basically referred to the verification of the caller who claims to the call the service. Verification of caller will be referring as service authentication. WCF offers various authentication mechanisms • No authentication:- Service does not authenticate its caller and it will allow all clients to access. • Windows authentication -Services use Kerberos when a windows domain service is available or NTLM when deployed in workgroup configuration. In this mode caller provides the windows credential tickets/token to the service authentication. • UserName/Password - Explicit username and password is provided to authenticate the service. • X509 certificates - In this mode of security, client will send his certificate information to the service communication. Service host will check and validate the caller certificate information to authenticate the service. • Custom mechanism - WCF allows developers to replace the build-in authentication mechanism by providing user own protocol and credential type for authentication. • Issue token - The caller and the service can both rely on a secure token service to issue the client a token that service identify and trust. E.g. windows card space
  37. 30. Transfer Security Mode Three aspects to transfer security to consider, they are: - • Message integrity – it ensures that message used in communication is not tampered by any malicious party. • Message privacy – It ensures confidentiality of the message so that no third part can even read the message. • Transfer security – it ensures that only authenticated user can able to read the content of the message.
  38. 31. Transport Security Mode (None) • When system is configured with ‘Transport’ mode, WCF uses secured communication protocol. The available secure transports are HTTPS, TCP, IPC and MSMQ. Transport security encrypts all communication on the channel and provides integrity, privacy and mutual authentication. It provides point-to-point security. • One of main disadvantage is that it can only guarantee transfer security point-to-point, meaning it secure only at channel level. Message inside the channel will not get secured. In case of distributed communication, multiple intermediaries between service and client will not be secure. • It is mainly used in intranet application, binding sample :-
  39. 32. Message Security Mode (Message) • In this mode of configuration, message will get encrypted. Encrypting the message rather than transport enables the service to communicate securely over non secure transport such as HTTP. It provides end-to-end security. • One of the disadvantages of message security is that it may introduce call latency due to its inherent overhead. • It is mainly used in internet application.
  40. 33. Mixed Transfer Security Mode (Credential) • It uses Transport security for message integrity, privacy and service authentication and it uses Message security for securing client credential. • One of disadvantage of the mixed mode is that it will secure only point-to-point as nature of Transport security.
  41. 34. Security Modes (Both) This mode Both transfer security mode uses both Transport security and Message security. So message is secured using Message security and then it is transferred to the service using secure transport. This mode will maximize the security but overload the performance.
  42. 35. Throttling WCF throttling provides some properties that you can use to limit how many instances or sessions are created at the application level. Performance of the WCF service can be improved by creating proper instance. Attribute Description maxConcurrentCalls Limits the total number of calls that can currently be in progress across all service instances. The default is 16. maxConcurrentInstances The number of Instance Context objects that execute at one time across a ServiceHost. The default is Int32.MaxValue. maxConcurrentSessions A positive integer that limits the number of sessions a ServiceHost object can accept. The default is 10.
  43. 36. Streaming • Client and Service exchange message using Streaming transfer mode, receiver can start processing the message before it is completely delivered. Streamed transfers can improve the scalability of a service by eliminating the requirement for large memory buffers. If you want to transfer large message, streaming is the best method. • The supported Steaming bindings are: - • BasicHttpBinding • NetTcpBinding • NetNamedPipeBinding
  44. 37. Streaming Restrictions • There are some restriction, when streaming is enabled in WCF, they are: - • Digital signatures for the message body cannot be performed • Encryption depends on digital signatures to verify that the data has been reconstructed correctly. • Reliable sessions must buffer sent messages on the client for redelivery if a message gets lost in transfer and must hold messages on the service before handing them to the service implementation to preserve message order in case messages are received out-of-sequence. • Streaming is not available with the Message Queuing (MSMQ) transport • Streaming is also not available when using the Peer Channel transport
  45. 38. Streaming and Binding Only the TCP, IPC, and basic HTTP bindings support streaming. With all of these bindings streaming is disabled by default. TransferMode property should be set according to the desired streaming mode in the bindings.
  46. 39. Streaming and Transport • Server transaction – Transaction setting propagated or initiated from server side • Client transaction – Transaction setting propagated or initiated from the client side • The main aim of the Streaming transfer mode is to transfer large size data, but default message size is 64K. So you can increase the message size using maxReceivedMessageSize attribute in the binding element as shown below.
  47. 40. Transaction • A transaction is a collection or group of one or more units of operation executed as a whole. It provides way to logically group single piece of work and execute them as a single unit. In addition, WCF allows client applications to create transactions and to propagate transactions across service boundaries. Recovery Challenge • The challenge we will phased and how to recover from it, therefore we need to consider the following : - • Consider a system maintained in consistent state, when application fail to perform particular operation, you should recover from it and place the system in the consistent state. • While doing singe operation, there will be multiple atomic sub operation will happen. These operations might success or fail. We are not considering about sub operation which are failed. We mainly consider about the success operation. Because we have to recover all these state to its previous consistence state. • Productivity penalty has to be payee for all effort required for handcrafting the recovery logic • Performance will be decreased because you need to execute huge amount of code.
  48. 41. Transaction Protocols (1/2) Best way to maintain system consistence and handling error-recovery challenge is to use transactions. Below figure gives idea about transaction.  Committed transaction: Transaction that execute successfully and transfer the system from consistence state A to B.  Aborted transaction: Transaction encounters an error and rollback to Consistence State A from intermediate state.  In-doubt transaction: Transactions fail to either in commit or abort. Consistent State B Committed Transaction Temporary Consistence State Abort Transaction Consistent State A
  49. 41. Transaction Protocols (2/2) As a developer we no need to concern about transaction protocols and transaction manager used by WCF. WCF itself will take care of what kind of transaction protocols should be used for different situation. Basically there are three different kinds of transaction protocols used by WCF. Attribute Description Lightweight • This protocol are used to manage the transaction with in same application domain • Best performance compare to other OleTx • This protocol are used to manage the transaction in an internet and in a windows environment WS-Atomic Transaction (WAST) • It can propagate transaction across firewalls. • Primary used in Internet with multiple transactions manager are involved
  50. 42. Transaction Propagation Transaction Flow Option Binding configuration Description NotAllowed transactionFlow="true" or transactionFlow="false" Client cannot propagate its transaction to service even client has transaction Allowed transactionFlow="true" Service will allow to flow client transaction. It is not necessary that service to use client transaction. Allowed transactionFlow="false" If service disallows at binding level, client also should disable at binding level else error will be occurred. Mandatory transactionFlow="true" Both Service and client must use transaction aware binding Mandatory transactionFlow="false" InvalidOperationException will be throw when service binding disables at binding level. Fault Exception will be thrown when client disable at its binding level. In WCF, transaction can be propagated across service boundary. This enables service to participate in a client transaction and it includes multiple services in same transaction, Client itself will act as service or client. We can specify whether or not client transaction is propagated to service by changing Binding and operational contract configuration
  51. 43. Transaction Resources • Transactional programming requires working with a resource that is capable of participating in a transaction, and being able to commit or roll back the changes made during the transaction. Such resources have been around in one form or another for decades. Traditionally, you had to inform a resource that you would like to perform transactional work against it. This act is called enlisting. Some resources support auto-enlisting. • Transaction Properties • Transaction can be said as pure and successful only if meets four characteristics. • Atomic - When transaction completes, all the individual changes made to the resource while process must be made as to they were all one atomic, indivisible operation. • Consistent - transaction must leave the system in consistent state. • Isolated - Resources participating in the transaction should be locked and it should not be access by other third party. • Durable - Durable transactions must survive failures.
  52. 44. Transaction Client/Server transaction mode • This settings ensures the service uses only the client’s transaction, Enable the TransactionFlow=true in binding configuration • Set TransactionFlowOption.Mandatory in the operation contract • Set TransactionScopeRequired=true in the operation contract • This setting ensures that service uses the client’s transaction if possible or a server side transaction when the client does not have a transaction. • Enable the TransactionFlow=true in binding configuration • Set TransactionFlowOption.Allowed in the operation contract • Set TransactionScopeRequired=true in the operation contract This ensures that the service always has a transaction, separated from any transaction its client may or may not have. • Disable the TransactionFlow=false in binding configuration • Set TransactionFlowOption.NotAllowed in the operation contract • Set TransactionScopeRequired=true in the operation contract
  53. 45. Transaction None transaction mode This setting ensures service does not use transaction • Disable the TransactionFlow=false in binding configuration • Set TransactionFlowOption.NotAllowed in the operation contract • Set TransactionScopeRequired=false in the operation contract
  54. 46. Operations • In classic object or component- oriented programming model offered only single way for client to call a method. Client will issue a call, block while the call was in progress, and continue executing once the method returned. • WCF will support classical Request-Replay model, along with that it also supports One-Way call(call and forget operation) and call-back(service to call back the client) • Three modes of communication between client and service are • Request- Replay • One-Way • Call-back
  55. 47. Request-Reply • By default all WCF will operated in the Request-Replay mode. It means that, when client make a request to the WCF service and client will wait to get response from service (till receiveTimeout). After getting the response it will start executing the rest of the statement. If service doesn't respond to the service within receiveTimeout, client will receive TimeOutException. • Apart from NetPeerTcpBinding and the NetMsmqBinding all other bindings will support request- reply operations. Client Service Request Response Wait State
  56. 48. One-Way • In One-Way operation mode, client will send a request to the server and does not care whether it is success or failure of service execution. There is no return from the server side, it is one-way communication. • Client will be blocked only for a moment till it dispatches its call to service. If any exception thrown by service will not reach the server. Client Service Request Continue Processing the next statement
  57. 49 .Callback Service • WCF provides the service to call the client. In which, service will act as client and client will act as service. HTTP protocols are connectionless nature, so it is not supported for callback operation. So BasicHttpBinding and WSHttpBinding cannot be used for this operation. • WCF support WSDualHttpBinding for call back operation. • All TCP and IPC protocols support Duplex communication. So all these binding will be used for callback operation. Client Service Request Response Duplex Proxy OnCallback() Callback instance call OnCallback() Operational Context Callback instance Instance Context Callback instance
  58. 50. What Is WCF RIA Service? • WCF RIA service is a framework to develop n-tier application for Rich Internet Application (RIA). It is mainly used in RIA applications like Silverlight, AJAX client, etc. It solves the major problem while developing business application like decoupling the resource access, application logic and presentation layer. WCF RIA service was introduced in Silverlight 4 with .NET framework 4, and it can be developed using visual studio 2010. • WCF RIA service will generate the code at the client side related to the service and domain entities declared at the server side. • RIA service exposes the data from server side to client side using Domain service, RIA service framework implements the each domain service as WCF service to access the data as business entity.
  59. 51. RIA Service Architecture Client Service Single Application Logic WCF Services WCF UI (Views) Application Logic Application Logic Data Access Logic DB
  60. 52. Problem Solved By RIA • To have best performance of the RIA application, app logic need to be available in client and server side. This problem is solved by auto generating the code at the client side while recompiling the project. • Asynchronous call – Async service call are supported in Domain service by using WCF infrastructure • Handling large data and data across different tier – Large amount of data can be access and filter using IQueryable object. Since entity objects used in domain service are serializable and so it can be access across different layer • Security/Access control – ASP.Net membership frameworks are integrated with RIA service to provide security systems to RIA service • Validation – Entity can be validated based using adding attribute to the class members
  61. 53. Domain Services • Domain services are WCF services that expose the business logic of a WCF RIA Services application. Domain service contains set of business related data operation and it is exposed as WCF service. • The Domain Service class is the base class for all classes that serve as domain services. • DomainServiceHost is the hosting class for domain service; internally • DomainServiceHost uses the WCF ServiceHost class to host the application. • A domain service class must be marked with the EnableClientAccessAttribute attribute to make the service available to the client project. The EnableClientAccessAttributeattribute is automatically applied to a domain service when you select the Enable client access check box in the Add New Domain Service Class dialog box. When the EnableClientAccessAttribute attribute is applied to a domain service, RIA Services generates the corresponding classes for the client project.
  62. 54. WCF RIA Domain Service Architecture Server Stack Domain Service Domain Service Host Client Stack Domain Service Domain Service Host RIAService WCF Service WCF Client Channel WCF Service Contract WCF Service Contract Client
  63. 55. Creating WCF Service (Step-by-Step) Step-by-step guide in creating a WCF Service Define .NET service interfaces to serve as the Service Contract Implement Service Contract in .NET class as Service type and configure its behaviour Configure the End Point where service will expose, by specifying A,B,C Host Service type in application using WCF hosting infrastructure At Client side, by using description of target End Point create PROXY and write the code against the proxy type. 1 2 3 4 5
  64. - END OF DECK By Abdul Khan – https://www.linkedin.com/in/abdul-khan-uk/
Publicité