Wcf services, data access, and other features

Published:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

5.1 Introduction

Microsoft Windows Communication Foundation (WCF) is one of the key technologies available in .NET Framework 3.0 and later versions. This session briefly introduces an overview of WCF services. The session also takes a look at the new data related controls in ASP.NET 3.5. As organizations grow global, there is a strong need for Web applications to adapt to global audiences and cultures. This session describes globalization and also discusses the support for accessibility in ASP.NET 3.5. Finally, the session explains about mobile applications in ASP.NET 3.5.

5.2 WCF Services

WCF is designed as unified programming model that helps to create distributed applications using various .NET technologies such as using Web services, .NET Remoting, Message Queue (MSMQ), Enterprise Services, and so forth. Through WCF, you can create a single service that can be exposed as named pipes, HTTP, TCP, and so on.

5.2.1 Creating a WCF Service with ASP.NET

ASP.NET and Visual Studio 2008 enable you to create and consume WCF services. The first step towards this is to define the service contract.

The steps to define a service contract are as follows:

1. Launch Visual Studio and select a new Web project of type WCF Service Application. This template defines a Web project for hosting the WCF service and will create a reference to System.ServiceModel.dll in the project. This assembly contains the WCF classes. The project template will also generate a default service named Service1.svc and a related contract file named IService1.cs. You can rename these two files appropriately. For example, you could name the project as TestServices and the service itself as NewService.

The contract file, INewService.cs, is a .NET Framework interface that includes the service attribute classes for the service class, the operations, and the members. The .svc.cs file is a class implementing this interface. A WCF Service application is automatically configured so that it can be hosted in IIS. It exposes a standard HTTP endpoint. The <system.servicemodel>section of the web.config file describes these settings.

An example of <system.servicemodel> section in web.config is shown in Code Snippet 1.

Code Snippet 1

<system.serviceModel>

<services>

<service name="TestServices.NewService"

behaviorConfiguration="TestServices.NewService">

<endpoint address="" binding="wsHttpBinding"

contract="TestServices.NewService.INewService">

<identity>

<dns value="localhost"/>

</identity>

</endpoint>

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

</service>

</services>

<behaviors>

<serviceBehaviors>

<behavior name="TestServices.NewServiceBehavior">

<serviceMetadata httpGetEnabled="true"/>

<serviceDebug includeExceptionDetailInFaults="false"/>

</behavior>

</serviceBehaviors>

</behaviors>

</system.serviceModel>

2. Implement the service contract. To implement the service, you start by defining the contract via the interface. For example, consider a scenario where you want to expose methods of a service that work with the Suppliers table in a Shipments database. Create a Supplier class inside ISupplierService.cs and mark it as a DataContract and marking each of its members as DataMember. Code Snippet 2 shows an example:

Code Snippet 2

[DataContract]

public class Supplier

{

// define a property

[DataMember]

public int SupplierCode { get; set; }

// define other properties

}

The next step is to define the methods of your interface in ISupplierService.cs and mark them with the OperationContract attribute. You need to mark the interface with the ServiceContract attribute as shown in Code Snippet 3.

Code Snippet 3

[ServiceContract]

public interface ISupplierService

{

[OperationContract]

Supplier GetSupplier(int supplierCode);

[OperationContract]

Supplier SaveSupplier(Supplier supplierper);

}

WCF will use the interface to expose a service. The service will be configured based on the web.config file.

The service interface is implemented inside the ISupplierService.svc.cs file as shown in Code Snippet 4.

Code Snippet 4

public class SupplierService : ISupplierService

{

confString =

ConfigurationManager.ConnectionStrings["SupplierString"].ToString();

public Supplier GetSupplier(int supplierId)

{

. . .

}

public void Display(Supplier supplier)

{

. . .

}

}

The contract is defined via the ISupplierService interface. The contract is implemented inside the SupplierService.svc file.

5.3.2 Calling or consuming the WCF service

The steps to configure one or more service endpoints and host the service in an application are taken care of by default while performing all the steps carried out until now. For example, an endpoint is configured via the default HTTP endpoint set up inside the web.config file and the service is hosted by IIS and ASP.NET.

Now finally, you can call the WCF service. You need to set a client to call the service. The client could be an ASP.NET Web site, a Windows application, or an application on a different platform.

Assuming that the client is going to be an ASP.NET Web site for the current scenario, the steps to call the service are as follows:

1. Create an ASP.NET Web site.

2. To generate a proxy class using Visual Studio 2008, right-click your Web site and select Add Service Reference. The Add Service Reference dialog box is displayed as shown in figure 5.2.

This dialog box allows you to define an address to your service. The concept of proxy class is similar to that in XML Web services - it is a WCF service client enabling you to work with the service without having to deal with the details of WCF. You can also create the proxy by using the ServiceModel Metadata Utility command-line tool (Svcutil.exe).

3. Specify an appropriate namespace in the Namespace box in the dialog box. This namespace will define the name for the proxy class that will be generated by Visual Studio.

4. Define binding and endpoint information. Actually, the Add ServiceReference dialog box generates the appropriate endpoint information automatically when you add the service reference. The web.config file will contain this information as shown in Code Snippet 5.

Code Snippet 5

<system.serviceModel>

<bindings>

<wsHttpBinding>

<binding name="WSHttpBinding_ISupplierService" closeTimeout="00:01:00"

openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"

bypassProxyOnLocal="false" transactionFlow="false"

hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288"

maxReceivedMessageSize="65536" messageEncoding="Text"

textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">

<readerQuotas maxDepth="32" maxStringContentLength="8192"

maxArrayLength="16384" maxBytesPerRead="4096"

maxNameTableCharCount="16384" />

<reliableSession ordered="true" inactivityTimeout="00:10:00"

enabled="false" />

<security mode="Message">

<transport clientCredentialType="Windows" proxyCredentialType="None"

realm="" />

<message clientCredentialType="Windows" negotiateServiceCredential="true"

algorithmSuite="Default" establishSecurityContext="true" />

</security>

</binding>

</wsHttpBinding>

</bindings>

<client>

<endpoint address="http://localhost:4392/SupplierService.svc"

binding="wsHttpBinding"

bindingConfiguration="WSHttpBinding_ISupplierService"

contract="NwServices.ISupplierService"

name="WSHttpBinding_ISupplierService">

<identity>

<dns value="localhost" />

</identity>

</endpoint>

</client>

</system.serviceModel>

There are two options to manage and edit the WCF configuration information: you can edit directly in web.config or you can use the Service Configuration Editor to manage your endpoints. Right-click the web.config file and choose Edit Wcf Configuration. This will launch the Service Configuration Editor dialog box.

Finally, you will create a Web page will call the service via the proxy class. Code Snippet 6 shows part of the code in the Web page that will instantiate the proxy class and call the service.

Code Snippet 6

. . .

SupplierServices.SupplierServiceClient testSupplier =

new SupplierServices.ShipperServiceClient();

SupplierServices.Supplier supplier = new SupplierServices.Supplier();

supplier = testSupplier.GetSupplier(supplierCode);

5.5 New Data Controls in ASP.NET 3.5

ASP.NET 3.5 defines several new data related controls including LinqDataSource, EntityDataSource, and ListView.

5.5.1 LinqDataSource

Language-Integrated Query (LINQ) is a set of features that adds query capabilities to .NET languages such as C#. LINQ enables you to query data from diverse data sources in an easy manner. The only condition is that these data sources must be LINQ-compatible, which means they must be supported by LINQ. LINQ can be used with SQL, XML files, objects (such as C# arrays and collections), and ADO.NET DataSets.

The LinqDataSource is new to ASP.NET 3.5 and Visual Studio 2008. It is used to retrieve data from a LINQ data model. This control enables you to display data from a database by using LINQ to SQL. Once you have generated data classes using the Object/Relational (O/R) designer, you can bind to those classes using the LinqDataSource control.

The ContextTypeName attribute is used in markup with the LinqDataSource to associate the database context of your LINQ-based data.

Consider a scenario where you have defined a DataContext class named EmpDataContext using Linq to SQL Classes in Visual Studio 2008. The following markup shows how you would connect to this class using the LinqDataSource control:

Code Snippet 7

<asp:LinqDataSource

ID="lnqEmp"

runat="server"

ContextTypeName="EmpDataContext"

EnableDelete="True"

EnableInsert="True"

EnableUpdate="True"

OrderBy="EmpCode"

TableName="Employees">

</asp:LinqDataSource>

Instead of typing the markup shown in Code Snippet 7, you can also use the Configure Data Source wizard to associate the DataContext class with the LinqDataSource control. This can be done using following steps:

1. Add a LinqDataSource control to the Web page.

2. Click the smart tag beside the control.

3. In the context menu that is displayed, select Configure Data Source. This will display the Configure Data Source wizard as shown in figure 5.3.

Figure 5.3: Configure Data Source Wizard for LinqDataSource

4. Proceed with the step by step procedure shown in the Configure Data Source wizard.

The LinqDataSource control allows you to define parameters, to indicate sorting, enable paging, and more. You can also define queries having Where and OrderBy clauses. The Where clause uses the WhereParameters representing a query string that filters the data on the query string. You can also bind a LinqDataSource control to a data-bound control.

5.5.2 EntityDataSource

The EntityDataSource control is new to the .NET Framework 3.5. The EntityDataSource control enables you to access data using the ADO.NET Entity Framework. Users who are familiar with data-bound controls will find the EntityDataSource control similar to the SqlDataSource, LinqDataSource, and ObjectDataSource controls. The EntityDataSource control enables you to bind data in an Entity Data Model (EDM) to Web controls on a page. You construct queries using snippets of Entity SQL code and assign them to the Where, OrderBy, GroupBy, and Select operators. You can supply parameter values to these operations from page controls, cookies, and other ASP.NET parameter objects. The EntityDataSource designer enables you to configure an EntityDataSource control easily at design time.

Similar to LinqDataSource, you can use the Configure Data Source wizard of the EntityDataSource control to initialize the data source. Figure 5.4 shows the wizard.

Initially, the wizard enables you to select a named connection from the Web.Config file or add a connection string to connect to the database. The second page of the wizard will have content depending on whether a Select statement configured by the options on the wizard is used or some other command text is used.

5.5.3 ListView

The ListView control is used to bind and display data items from a data source. The ListView provides features that support pagination, sorting, and grouping of items. Using the ListView control, you can perform edit, insert, and delete operations on data without the need for any code.

You can bind the ListView control to data by using the DataSourceID property. This enables you to bind the ListView control to a data source control, such as the SqlDataSource control. You can also bind the ListView control to data by using the DataSource property. This enables you to bind to various objects, which includes ADO.NET datasets and data readers and in-memory structures such as collections. This approach requires that you write code for any additional functionality such as sorting, paging, and updating.

Items that are displayed by a ListView control are defined by templates, similarly to the DataList and Repeater controls. The ListView control lets you display data as individual items or in groups.

You define the main layout of a ListView control by creating a LayoutTemplate template. The LayoutTemplate must include a control that acts as a placeholder for the data. You define content for individual items using the ItemTemplate template. This template typically contains controls that are data-bound to data columns or other individual data elements.

Code Snippet 8 shows a ListView control that displays names of categories from the Categories table in Library database.

Code Snippet 8

<head runat="server">

<title>ListView Demo</title>

<style type="text/css">

.table

{

border: thin #000000 solid;

border-collapse: collapse;

border: 1px solid #000000;

}

table td

{

border: 1px solid #FF0000;

}

</style>

</head>

<body>

<form id="form1" runat="server">

<div>

</div>

<br />

<br />

<asp:ListView runat="server" ID="ListView1" DataSourceID="SqlDataSource1">

<LayoutTemplate>

<table runat="server" id="table1" class="table">

<tr runat="server" id="itemPlaceholder">

</tr>

</table>

</LayoutTemplate>

<ItemTemplate>

<tr id="Tr1" runat="server">

<td id="Td1" runat="server">

<%-- Data-bound content. --%>

<asp:Label ID="NameLabel" runat="server" Text='<%#Eval("Category") %>' />

</td>

</tr>

</ItemTemplate>

</asp:ListView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:LibraryConnectionString %>"

SelectCommand="SELECT [CategoryID], [Category] FROM [BookCategories]"></asp:SqlDataSource>

The output of this markup is seen in figure 5.6.

5.6 Globalization

  • .NET Framework 4
  • .NET Framework 3.0
  • Visual Studio 2005
  • Visual Studio .NET 2003

ASP.NET allows you to develop Web applications that can be accessed by millions of users across the globe. This means that the Web applications should be created taking into consideration the requirements of users from various parts of the world. Thus, you need to internationalize your application to make it accessible to users belonging to different countries, regions, cultures, languages, and so on. Globalizationinvolves the process of developing Web applications that can be used by users from different parts of the world. These Web applications will be independent of the language and culture.

In short, globalizing an application involves making your application readable to a wide range of users irrespective the cultural and regional differences.

Consider a scenario of a medical research company in New York. The company has created a Web application that displays the results of different researches carried out by the company. The Web application is created considering a wide range of users of different languages and cultures. This means that the Web site is culture and language specific. Thus, for a user from United States, the Web site content appears in English and for the user from France, the Web site content appears in French, and so on. But, the company wants to follow a standard format while representing the medical signs and symbols. This means that irrespective of the user's location, the signs and symbols should appear same. To implement this, developers can globalize the Web application.

Using ASP.NET, you can create Web applications that can automatically adjust culture, and format dates and currency according to user requirements.

ASP.NET supports globalization by providing the System.Globalization namespace. The System.Globalization namespace provides a set of classes to build applications that can be supported across the globe. These classes allow you to deal with various globalization issues such as culture, region, calendar support, and date-time formatting. Table 5.1 lists the commonly used classes of the System.Globalizationnamespace.

Class

Description

Calendar

This class represents days in weeks, months, and years. It is the base class for other culture specific calendars such as GregorianCalendar, JapaneseCalendar, and KoreanCalendar

CultureInfo

This class provides culture-specific information such as name of the culture and language

NumberFormatInfo

This class represents the way the numeric values are formatted and displayed for a specific culture

RegionInfo

This class provides information about country/region such as country/region name and two letter code defined in ISO 3166

Table 5.1: Commonly Used Classes of System.Globalization

For example, to display the currency symbol of the current culture in your Web application, the code shown in Code Snippet 9 will be used.

Code Snippet 9

CultureInfo ci = System.Threading.CurrentThread.CurrentCulture;

NumberFormatInfo nfi = ci.NumberFormat;

Response.Write("Currency Symbol: " + nfi.CurrencySymbol + "<BR>");

If the current culture is US, the currency symbol displayed as a result of Code Snippet 9 will be $.

You can set the culture or an ASP.NET Web page declaratively using one of two approaches:

  • Add a globalization section to the web.config file, and then set the uiculture and culture attributes, as shown:

    <globalization uiCulture="es" culture="es-MX" />

    This sets the UI culture and culture for all pages,

  • Set the Culture and UICulture attributes of the @Page directive, as shown in the following example:

    <%@ Page UICulture="es" Culture="es-MX" %>

    This sets the UI culture and culture for an individual page,

  • .NET Framework 4

  • Visual Studio 2005

    A resource file is used to store user interface strings for translating the application into other languages. It is a useful component in the process of globalization and localization. Resource files are stored in XML format and contain strings, image file paths, and other resources. This is because you can create a separate resource file for each language into which you want to translate a Web page.

    The steps to create a resource file are as follows:

    1. Ensure that your Web site has a folder such as App_GlobalResources in which to store the resource file. You can add such a folder by right-clicking on the Website name in Solution Explorer and selecting Add ASP.NET Folder and then selecting App_GlobalResources as shown in figure 5.7.
    2. Right-click the App_GlobalResources folder, and then click Add New Item. This will create a resource file,
    3. In the Add New Item dialog box, under Visual Studio installed templates, click Resource File.
    4. In the Name box, specify a name for the resource file and then click Add. The Resources Editor pane is displayed where you can type names (keys), values, and optional comments indicating each resource item.
    5. Type appropriate key names and values for each resource that you need in your application, and then save the file.
    6. To create resource files for additional languages, copy the file in Solution Explorer or in Windows Explorer, and then rename it using the syntax filename.language-culture.resx. For instance, if you create a global resource file named Resources.resx for translation to Spanish (Mexico), you will name the copied file Resources.es-mex.resx. Open the copied file and translate each value, leaving the names (keys) the same.
    7. Perform and repeat steps 6 and 7 for each additional language that you want to use.

    5.8 Accessibility Support in ASP.NET

    • .NET Framework 4
    • .NET Framework 3.0
    • Visual Studio 2005

    Accessible Web applications enable people with disabilities to use assistive technologies, such as screen readers, to work with Web pages. ASP.NET can help you create accessible Web applications.

    ASP.NET controls support accessibility standards including Web Content Accessibility Guidelines 1.0 (WCAG) to a great extent. However, sometimes ASP.NET controls produce results that fail to comply with all accessibility standards. In such cases, you will need to manually configure the controls for accessibility.

    You can configure keyboard support for your pages in ASP.NET using one of these approaches:

    • Set tab order for controls using the TabIndex property.
    • Specify a default button for a form or Panel control by setting the DefaultButton property.
    • Define access keys for button controls by setting the AccessKey property.
    • Use Label controls with text boxes, which let you define access keys for the text boxes.

    5.9 Mobile Applications in ASP.NET 3.5

    Today, in major parts of the world, a mobile phone is no longer a luxury but a necessity. Mobile devices such as smartphones, Personal Digital Assistants (PDAs), and others have become essential gadgets and support many powerful features that make life easier and well-organized. These mobile devices can have a number of applications installed on them. Mobile application development is therefore considered to be a crucial part of a developer's skillset. As an ASP.NET developer, it is imperative for you to be familiar with the creation of both Web and mobile applications.

    5.9.1 Mobile Application Creation in ASP.NET 3.5

    In earlier versions of Visual Studio before Visual Studio 2008, there was built-in designer support for developing mobile Web applications. The IDE provided an application template using which you could create a new mobile Web application. An item template allowed you to customize the display and appearance of controls in Design View. Using the designer, you could work with mobile Web forms and mobile Web user controls in Design View. The IDE also provided toolbox and design-time layout support which made the task of working with ASP.NET mobile Web applications simple and easy.

    However, from Visual Studio 2008 onwards, there is no built -in designer support for developing mobile Web applications. You can still create and work with mobile Web applications by using downloaded templates from the Web. The steps to do this are listed below:

    1. Download ASP.NET Mobile Templates.zip from http://blogs.msdn.com/b/webdevtools/archive/2007/09/17/tip-trick-asp-net-mobile-development-with-visual-studio-2008.aspx
    2. Extract the zip file. This will result in a number of other zip files.
    3. Copy the zip files with filenames ending with "_cs" to: [My Documents]\Visual Studio 2008\Templates\ItemTemplates\Visual C#.
    4. Restart Visual Studio.
    5. Create an empty Website as shown in Figure 5.8.
    6. Select WebsiteàAdd New Item. The Add New Item dialog box will display the newly added templates available as shown in figure 5.9.
    7. Select the template Mobile Web Form as shown in figure 5.10 and click Add.

    A mobile Web form will be added to the Website application.

    Switch to the code view. You will observe that the Default class inherits from System.Web.UI.MobileControls.MobilePage.

    An alternative way of creating Mobile Web forms in Visual Studio 2008 is to add a Web form to your application and then modify the page class declaration to inherit from System.Web.UI.MobileControls.MobilePage.

    Once the Mobile Web page is created using either of these two approaches, you can then place mobile Web controls onto the page by dragging them from the Toolbox or by typing markup and attributes.

    Code Snippet 10 demonstrates how to create a simple mobile form with a Panel and a Label control.

    Code Snippet 10

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>

    <html xmlns="http://www.w3.org/1999/xhtml" >

    <body>

    <mobile:Form id="Form1" runat="server" BackColor="#99ffcc">

    <mobile:Label Name="lblMessage" runat="server" Font-Bold="True" ForeColor="Blue"

    Font-Size="Large">Welcome, this is exciting</mobile:Label>

    <br></br>

    <mobile:Image ID="Image1" Runat="server" ImageUrl="Garden.jpg">

    </mobile:Image>

    </mobile:Form>

    </body>

    </html>

    Save and build the application.

    5.9.2 Executing Mobile Applications

    The steps to test this application are as follows:

    1. Install the Windows Mobile Device Center if it is not already installed.
    2. Install Windows Mobile 6.0 Professional SDK Refresh if it is not already installed.
    3. Select Tools->Device Emulator Manager in the Visual Studio 2008 IDE.
    4. Right-click Windows Mobile 6.0 Professional Emulator in the Device Emulator Manager dialog box and select Connect.
    5. Right-click Windows Mobile 6.0 Professional Emulator in the Device Emulator Manager dialog box and select Cradle. Windows Mobile Device Center (WMDC) is opened. Ensure that the connection setting on WMDC is set to DMA. If you are using a Work network to connect to the Internet, then select "This computer connects to Work Network."
    6. Launch Internet Explorer on the emulator and navigate to the URL of your mobile Web application. Assuming that the local machine name is test, the output will be as shown in figure 5.11. You can also use the IP address of the machine instead of machine name.

    5.9.3 Mobile Device Capabilities

    People around the world use different mobile devices. These devices may differ in display sizes and capabilities. If a Web developer develops a Web application for a specific mobile device, it may not work when exported to other mobile devices. To overcome this problem, there is a need of some means of device filtering. Device filtering is the process of customizing mobile Web server controls to correctly display them on select mobile devices.

    Using device filters, mobile Web applications can customize the appearance of controls for specific hardware devices. The customization is based on the capabilities of the hardware device being used to browse the application. Device filters are used to customize the behavior of Web server controls depending on the browser or device that accesses them.

    Typically, the web.config file stores device capabilities in the <deviceFilters> section.

    By default, your mobile Web application in .NET Framework 3.5 and Visual Studio 2008 may not have a web.config file. To add it, launch the Add New Item dialog box and select the Mobile Web Configuration item template as shown in figure 5.12.

    The web.config will contain following device filters by default in the <deviceFilters> section:

    <deviceFilters>

    <filter name="isJPhone" compare="Type" argument="J-Phone" />

    <filter name="isHTML32" compare="PreferredRenderingType"

    argument="html32" />

    <filter name="isWML11" compare="PreferredRenderingType" argument="wml11"

    />

    <filter name="isCHTML10" compare="PreferredRenderingType"

    argument="chtml10" />

    <filter name="isGoAmerica" compare="Browser" argument="Go.Web" />

    <filter name="isMME" compare="Browser" argument="Microsoft Mobile

    Explorer" />

    <filter name="isMyPalm" compare="Browser" argument="MyPalm" />

    <filter name="isPocketIE" compare="Browser" argument="Pocket IE" />

    <filter name="isUP3x" compare="Type" argument="Phone.com 3.x Browser" />

    <filter name="isUP4x" compare="Type" argument="Phone.com 4.x Browser" />

    <filter name="isEricssonR380" compare="Type" argument="Ericsson R380" />

    <filter name="isNokia7110" compare="Type" argument="Nokia 7110" />

    <filter name="prefersGIF" compare="PreferredImageMIME"

    argument="image/gif" />

    <filter name="prefersWBMP" compare="PreferredImageMIME"

    argument="image/vnd.wap.wbmp" />

    <filter name="supportsColor" compare="IsColor" argument="true" />

    <filter name="supportsCookies" compare="Cookies" argument="true" />

    <filter name="supportsJavaScript" compare="Javascript" argument="true" />

    <filter name="supportsVoiceCalls" compare="CanInitiateVoiceCall" argument="true" />

    </deviceFilters>

    ASP.NET provides the HasCapability() method in the MobileCapabilities class to determine device capabilities for mobile devices. The method takes two parameters. The first is a string specifying a delegateName that will point to the device evaluation method, property name, or so forth and the second parameter is any value that the capabilityName argument requires. The second parameter is optional.

    The HasCapability() method enables you to determine through code whether the current device matches any device filter specified in the web.config file.

    Code Snippet 11 shows the use of HasCapability() method.

    Code Snippet 11:

    try

    {

    bool result = ((MobileCapabilities)Request.Browser).HasCapability("supportsColor", null);

    txtvwMessage.Text = answer.ToString();

    }

    catch (ArgumentOutOfRangeException )

    {

    txtvwMessage.Text = "false";

    }

    Here, the code tries to check whether there is any device filter named supportsColor defined in the web.config file. If yes, it assigns the true value to the TextView control, txtvwMessage. If there is no such filter defined, an ArgumentOutOfRangeException is raised and a value of false is assigned to the TextView control, txtvwMessage. In the web.config file shown earlier, there is a filter named supportsColor. Therefore, the outcome of Code Snippet 11 is that the TextView displays true.

    5.9.4 Using the DeviceSpecific Control

    The process of rendering a control differently based on the browser that requested the Web page is called adaptive rendering. You use the DeviceSpecific element in ASP.NET mobile applications to implement adaptive rendering.

    One or more <Choice> elements containing different versions of the content targeting different devices are placed inside the <DeviceSpecific> element, as shown in Code Snippet 12.

    Code Snippet 12

    <mobile:Form id="frmTest" runat="server">

    <mobile:Label Runat="server" ID="Label1">

    Welcome

    <DeviceSpecific>

    <Choice Filter="isPocketIE" Font-Italic="True" Font-Name="Arial

    Black"/>

    <Choice Filter=" isNokia7110" ForeColor="Magenta" />

    </DeviceSpecific>

    </mobile:Label>

    </mobile:Form>

    Choices are evaluated from the first <Choice> element to the last. Each choice includes a Filter element. If the device satisfies the Filter then the content within that choice is displayed to the client. The last choice in the above example has no Filter. The content in this choice displays on all of the devices that satisfy none of the filters.

    The Filter attribute of the <Choice> element can also refer to a filter in the web.config file.

    Summary

    • WCF is a unified programming model that helps to create distributed applications using .NET technologies.
    • ASP.NET 3.5 defines several new data related controls including LinqDataSource, EntityDataSource, and ListView.
    • Globalization involves the process of developing Web applications that can be used by users from different parts of the world.
    • A resource file is used to store user interface strings for translating the application into other languages and plays an important role in globalization.
    • Most ASP.NET controls provide built-in support for accessibility in Web applications.
    • ASP.NET 3.5 enables you to develop mobile Web applications.
    • Mobile device capabilities differ from device to device and are specified using <deviceFilters> in web.config file.
  • Writing Services

    Essay Writing
    Service

    Find out how the very best essay writing service can help you accomplish more and achieve higher marks today.

    Assignment Writing Service

    From complicated assignments to tricky tasks, our experts can tackle virtually any question thrown at them.

    Dissertation Writing Service

    A dissertation (also known as a thesis or research project) is probably the most important piece of work for any student! From full dissertations to individual chapters, we’re on hand to support you.

    Coursework Writing Service

    Our expert qualified writers can help you get your coursework right first time, every time.

    Dissertation Proposal Service

    The first step to completing a dissertation is to create a proposal that talks about what you wish to do. Our experts can design suitable methodologies - perfect to help you get started with a dissertation.

    Report Writing
    Service

    Reports for any audience. Perfectly structured, professionally written, and tailored to suit your exact requirements.

    Essay Skeleton Answer Service

    If you’re just looking for some help to get started on an essay, our outline service provides you with a perfect essay plan.

    Marking & Proofreading Service

    Not sure if your work is hitting the mark? Struggling to get feedback from your lecturer? Our premium marking service was created just for you - get the feedback you deserve now.

    Exam Revision
    Service

    Exams can be one of the most stressful experiences you’ll ever have! Revision is key, and we’re here to help. With custom created revision notes and exam answers, you’ll never feel underprepared again.