Author’s note
Lately, I noticed surge in interest to our products for SQL Server Reporting Services. I’m getting quite a lot of questions from our users regarding the products architecture, their components and interaction between these components. I’m going to write a series of articles on this topic. In this series, I’m going to describe the Silverlight Viewer for Reporting Services structure, the components which are included in it (I’m going to give precise description of each component), and interaction between the components. The first article will cover general questions on implementation of WCF-service. The second article will cover the SSRS structure and peculiarities of implementation of the custom extension. And finally, the third final article will tell how the interaction between the components occurs in our component, Silverlight Viewer for Reporting Services.
So, let’s begin with description of WCF.
Base WCF Service Architecture
In general terms, Windows Communication Foundation – is a unified integrated environment for the creation of secure, reliable, distributed applications. WCF is based on interaction between two entities:
- WCF service
- WCF client
You can read what is WCF service here:
http://msdn.microsoft.com/en-us/library/ee958158.aspx
http://msdn.microsoft.com/en-us/library/bb522673.aspx
And I will briefly touch on the basic issues of implementation of WCF service.
WCF service
WCF service is based on the interface, which sets a contact between a service and a client.
In order to create WCF service I should follow the steps as described below.
The service should be marked by the ServiceContractAttribute attribute.
Methods and functions WCF service provides access to should be marked by the OperationContractAttribute attribute.
public interface IWcfService
{
[OperationContract]
string GetData();
}
I need to create the data model (analogous to the server part model) on the client’s part. In this case, when the server returns the object in response to the query, only marked fields will be serialized.
To mark fields for the serialization I can use the following attributes:
DataContractAttribute – the attribute for marking the data type;
DataMemberAttribute – the attribute for marking the type member which should be serialized.
For example:
public class DataClass
{
[DataMember]
public string FirstName { get; set; }
[DataMember]
public string LastName { get; set; }
}
When the interface and its methods have been determined, they are encapsulated into the class.
A single class of WCF service can implement multiple contracts.
WCF service is available when the endpoints are used. The endpoint is the only way to interact with this service; it is impossible to get access to it by direct reference (Figure 1).
Figure 1: A WCF service class runs in a host process and exposes one or more endpoints.
The endpoint consists of an address, binding and contract. The address sets server location; this can be URL-address, FTP-address, and network or local path. The binding sets the way of interaction with this service.
The WCF bindings provide flexible model for setting the protocol (for example HTTP or FTP), security mechanism (for example Windows authentication or users’ names and passwords). The contract includes operations which are provided by the class of WCF service (Figure 2).
Figure 2: Each endpoint has an address, binding, and contract.
One WCF service can have several endpoints. This allows the interaction of different clients with one and the same services in different ways. For example, the banking service can provide one endpoint for employees, and the other – for external clients. And each endpoint uses the different address, binding and/or contract.
WCF client
WCF client consists of proxy that allows the application to interact with the service (WCF) and the endpoint. This endpoint corresponds to the endpoint set for this service.
The proxy is set in the app.config (or web.config) file on the client side and includes information on the types and methods provided by the service. In case, when the service provides several endpoints, the client can select one, which best fulfills his requirements. For example, the client can select the way of interaction via HTTP protocol and Windows authentication.
After WCF client is created, I refer to its service in the code in the way I refer to any other object. For example, to invoke the GetData method (which is described above) I can write the following code:
client.GetDataCompleted += new EventHandler(client_GetDataCompleted);
client.GetDataAsync();
Accordingly, the response handling can be executed as follows:
{
// data obtained from the server
string data = e.Result;
}
The scheme of interaction of the client application and the service is shown in the Figure 3.
Figure 3: WCF client can use proxy to access service.
This article covers the basic info about WCF service and WCF client. Next articles will describe Silverlight Viewer and its components.
Of course, WCF technology has a wide application in the development of projects. You are welcome to share your experience with our blog readers. Your comments are welcome!