implements at least one service contract, which defines the operations this service exposes. The class might also provide an explicit which defines the data those operations data contract, convey. This section looks at both, beginning with service contracts. Defining Service Contracts service class implements methods for its clients to use. The creator of the class determines which of its methods are exposed as client-callable operations by specifying that they are part of some service contract. To do this, a developer uses the WCF-defined attribute In fact, a service class is just a class that either is itself marked with the ServiceContract. attribute or implements an interface marked with this attribute. Both ServiceContract options make sense in different situations, and both will be described shortly. First, however, here’s a short description of the class, called that will RentalReservations, be used as an example throughout this section. It’s an implementation of the basic functions in the car rental reservation application described earlier, and it has four methods: which allows a client to determine the availability of a particular vehicle class at a Check, certain location on specific dates. This method returns a Boolean value indicating whether there is availability. which allows a client to reserve a particular type of vehicle at a certain location Reserve, on specific dates. This method returns a confirmation number. which allows a client to cancel an existing reservation by providing its Cancel, confirmation number. This method returns a Boolean value indicating whether the cancellation succeeded. which returns a count of how many reservations currently exist. Unlike the GetStats, other methods in this class, can be invoked only by a local administrator, not GetStats by clients of the service. With this in mind, here’s an abbreviated C# example that uses the class-based approach to define as a service class: RentalReservations using System.ServiceModel; [ServiceContract] class RentalReservations { [OperationContract] public bool Check(int vehicleClass, int location, string dates) { bool availability; // code to check availability goes here return availability; } [OperationContract] public int Reserve(int vehicleClass, int location, string dates)
implements at least one service contract, which defines the operations this service exposes. The class might also provide an explicit data contract, which defines the data those operations convey. This section looks at both, beginning with service contracts. Defining Service Contracts service class implements methods for its clients to use. The creator of the class determines which of its methods are exposed as client-callable operations by specifying that they are part of some service contract. To do this, a developer uses the WCF-defined attribute ServiceContract. In fact, a service class is just a class that either is itself marked with the ServiceContract attribute or implements an interface marked with this attribute. Both options make sense in different situations, and both will be described shortly. First, however, here’s a short description of the class, called RentalReservations, that will be used as an example throughout this section. It’s an implementation of the basic functions in the car rental reservation application described earlier, and it has four methods: Check, which allows a client to determine the availability of a particular vehicle class at a certain location on specific dates. This method returns a Boolean value indicating whether there is availability. Reserve, which allows a client to reserve a particular type of vehicle at a certain location on specific dates. This method returns a confirmation number. Cancel, which allows a client to cancel an existing reservation by providing its confirmation number. This method returns a Boolean value indicating whether the cancellation succeeded. GetStats, which returns a count of how many reservations currently exist. Unlike the other methods in this class, GetStats can be invoked only by a local administrator, not by clients of the service. With this in mind, here’s an abbreviated C# example that uses the class-based approach to define RentalReservations as a service class: using System.ServiceModel; [ServiceContract] class RentalReservations { [OperationContract] public bool Check(int vehicleClass, int location, string dates) { bool availability; // code to check availability goes here return availability; } [OperationContract] public int Reserve(int vehicleClass, int location, string dates)
Introducing_WCF_in_.NET_Framework_3.5_v1.0.docx