WCF Tutorial, Part 2: Create a Simple Service and Client

01. December 2013 WCF 0

The following steps will be creating a simple service which is used to reserve a room.

Task 1: Define Service and Data Contract

Create the DataContract

  • Open Visual Studio
  • Create an Empty Solution called RoomReservation
  • Add a Class Library project to the solution and name it RoomReservationContracts
  • Create a class called RoomReservation

    This class will be used to represent data from which retrieves from database and will be using across the network.

RoomResercation.cs

  • INotifyPropertyChanged Interface is used to notify clients, typically binding clients, that a property value has changed.
  • DataContract and DataMember attributes used to determine that the class is used to sending data across WCF service.
  • A DataContract is a formal agreement between a service and a client that abstractly describes the data to be exchanged. That is, to communicate, the client and the service do not have to share the same types, only the same data contracts. A data contract precisely defines, for each parameter or return type, what data is serialized (turned into XML) to be exchanged.
  • StringLengthAttribute Class specifies the minimum and maximum length of characters that are allowed in a data field. It is used for both validating user input as well as define column schemas on creating the database table.

Create the Service Contract

  • Add a new class to the project called IRoomService

IroomService.cs

  • Operations offered by the service can be defined by an interface.
  • The service contract is defined with the attribute ServiceContract.
  • The operations defined by the service have the attribute OperationContract.

Leave a Reply

Your email address will not be published. Required fields are marked *