1 / 43

Windows Communication Foundation and Web Services

Windows Communication Foundation and Web Services. WCF (Introduction). It’s Microsoft’s current inter-machine communication foundation used to integrate HTTP requests and responses Web Services Messaging Lower-level TCP/IP Ajax / REST services And everything else. WCF Fundamentals.

metta
Télécharger la présentation

Windows Communication Foundation and Web Services

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. Windows Communication Foundation and Web Services

  2. WCF (Introduction) • It’s Microsoft’s current inter-machine communication foundation used to integrate • HTTP requests and responses • Web Services • Messaging • Lower-level TCP/IP • Ajax / REST services • And everything else

  3. WCF Fundamentals • Simply put, it’s a set of APIs used to send messages between services and clients • It’s based on messages (HTTP, MSMQ, …) • Messages are sent between endpoints • Messages are sent using a transport protocol • HTTP / TCP …

  4. WCF Model (1)

  5. WCF Model (2)

  6. WCF Model (Contracts) • Contracts describe the precise format of messages • This is done using SOAP (or other protocol) • The service contract defines the interface to the outside world • We are talking about the format of • Function calls • Parameters • Return types • These are message signatures • The programming model defines how we write the code to do all of this

  7. WCF Model (Contract)Request-Reply • Request-Reply services • This is the default type of service • Clients make a request for service (synchronously or asynchronously) • Clients receive a response • Duplex services

  8. WCF Model (Contract)One Way • In a One-Way service, the client sends a request but does not expect a response • To detect errors, create two One-Way service contracts

  9. WCF Model (Contract)Duplex • Both endpoints can send messages independently • These are implemented using the idea of a callback • To implement, create two interfaces • The first is the one-way client interface • The second is the callback contract • Refer to http://msdn.microsoft.com/en-us/library/ms731064(v=vs.110).aspx

  10. WCF Model (Service Runtime) • This layer defines the behavior of the runtime service (server configuration) • We configure the service runtime using behaviors • There is much detail here beyond the scope of this course

  11. WCF Model (Service Runtime) • How many messages are processed at a time • InstanceContextMode / ConcurrencyMode • How many instances of a server can run (singleton) • InstanceContextMode • Threading and reentrancy • ConcurrencyMode

  12. WCF Model (Messaging) • Transport channels are of two types • Transport channels send and receive messages • TCP, HTTP, MSMQ • Protocol channels implement the messaging protocols • http

  13. WCF Model (Hosting) • Simply put, it’s where the application runs (is hosted) • Might be IIS or WAS

  14. WCF Model (Hosting)

  15. WCF Model (Hosting)

  16. WCF Model (Hosting - IIS) • This is the easiest way to host your service • IIS treats the service as an ASP.NET Web Site • If you are using IIS6, then only HTTP and HTTPS are supported • You can create a self-hosted console application that listens for requests at a particular port • We can also host through Azure Services ( I have no idea how to do this)

  17. WCF and Web Services • WCF has changed the .net picture of Web Services • They used to be a standalone product type etc… • They are now just another service within the context of WCF

  18. The Goal of Web Services • Supply a standard means for e-commerce applications to communicate using different hardware and software platforms • Supply a way for legacy applications to communicate • Provide a universal way to discover the available services and the methods supplied by a particular service so that any consumer can call those methods

  19. Logical Web Service Model

  20. Calling Web Service Methods (Illustration)

  21. Web Service Vendors • IBM – WebSphere Studio Application Developer • SAP – SAP Web Application Server • SUN – Sun ONE Web Services Platform Developer Edition • And of course Microsoft and Visual Studio .NET • Others are likely to follow • No matter the vendor, Web services will always work the same way • Any consumer should work with any provider

  22. Web Service Protocols • Web services provide a hardware and software agnostic way to call remote functions and return data from those remote functions • Protocols • HTTP is the message transfer agent • Simple Object Access Protocol (SOAP) • Web Service Description Language (WSDL)

  23. SOAP • Encapsulates an XML document for the purpose of serialization • SOAP messages are exchanged between providers and consumers • SOAP is a message envelope containing an XML document • Consumers send SOAP requests to providers • Requests are method calls serialized into an XML document • Providers send responses to consumers in the form of another XML document • All of this happens behind the scenes and is not that significant to the developer

  24. WSDL • A WSDL document fully describes a Web service • All methods are defined • Method signatures are also defined • A WSDL document is a well-formed and valid XML document • A WSDL document is almost always generated automatically • They become very complex very quickly • .NET uses the WSDL document along with Intellisense technology to display member calling conventions (signature prototypes)

  25. C# Attributes • C# Attributes allow metadata to be compiled into an application • They are used for many purposes – Web services being one • Reflection

  26. Creating A Web Service • Create a new Web side using the WCF Service project type

  27. Web Service Lifecycle • Design the service contract • Implement the service contract • This is done via attributes • Configure the service endpoints • Host the service • Build client applications

  28. Web Service Implementation (Steps) • Declare the members of the interface that will be implemented in the .svc file • Implement those members in the corresponding class

  29. Service Contract • A service exposes one or more service operations • A ServiceContract defines the types of messages used in a conversation • A ServiceOperation defines the messages themselves

  30. Service Contract (Example 1)

  31. Service Contract (Example 2) • Use a class instead of creating an interface and implementing that interface

  32. Data Contract • Simply put, simple types do not require a data contract. Complex types do • Serializable parameters do not require a data contract • A DataContract describes a type that will be serialized by the service • A DataMember describe the members of the DataContracttype

  33. Data Contract (Example 1)

  34. Configure Service Endpoints (1) • Communication occurs through service endpoints and four properties • Address of the endpoint • A binding that specifies how a client can communicate with the endpoint • A contract the defines the allowable operations • Local implementation details

  35. Configure Service Endpoints (2) • We can configure endpoints via • Code • In the config (web.config) file

  36. Configure Service Binding (1) • Most bindings are provided with WCF • Use BasicHttpBinding for most Web services

  37. Host the Service • IIS must be installed on the server

  38. Compiling the Service • The service is compiled the same way as any other .NET app. • If you run it, you see a “special” test client window • The code is generated by .NET itself

  39. Test Service (Illustration 1)

  40. Test Service (Illustration 2)

  41. Creating the Test Client • Create a WPF or Windows forms application • Insert the template code created by Svcutil.exe into this project • While the service is running locally, add a service reference • In a production app, you will have this URL • Change the name of the endpoint in app.config

  42. Adding the Service Reference (Example)

  43. Changing the endpoint • Rename the end point in the app.config file

More Related