Wcf services, data access, and other features

Wcf services, data access, and other features

5.1 Introduction

Microsoft Windows Communication Foundation ( WCF ) is one of the cardinal engineerings available in.NET Framework 3.0 and ulterior versions. This session briefly introduces an overview of WCF services. The session besides takes a expression at the new informations related controls in ASP.NET 3.5. As organisations grow planetary, there is a strong demand for Web applications to accommodate to planetary audiences and civilizations. This session describes globalisation and besides discusses the support for handiness in ASP.NET 3.5. Finally, the session explains about nomadic applications in ASP.NET 3.5.

5.2 WCF Services

WCF is designed as incorporate programming theoretical account that helps to make distributed applications utilizing assorted.NET engineerings such as utilizing Web services, .NET Remoting, Message Queue ( MSMQ ) , Enterprise Services, and so forth. Through WCF, you can make a individual service that can be exposed as named pipes, HTTP, TCP, and so on.

5.2.1 Making a WCF Service with ASP.NET

ASP.NET and Visual Studio 2008 enable you to make and devour WCF services. The first measure towards this is to specify the service contract.

The stairss to specify a service contract are as follows:

1. Launch Ocular Studio and choose a new Web undertaking of type WCF Service Application. This templet defines a Web undertaking for hosting the WCF service and will make a mention to System.ServiceModel.dll in the undertaking. This assembly contains the WCF categories. The undertaking templet will besides bring forth a default service named Service1.svc and a related contract file named IService1.cs. You can rename these two files suitably. For illustration, you could call the undertaking as TestServices and the service itself as NewService.

The contract file, INewService.cs, is a.NET Framework interface that includes the service property classes for the service category, the operations, and the members. The.svc.cs file is a category implementing this interface. A WCF Service application is automatically configured so that it can be hosted in IIS. It exposes a standard HTTP end point. The & lt ; system.servicemodel & gt ; subdivision of the web.config file describes these scenes.

An illustration of & lt ; system.servicemodel & gt ; subdivision in web.config is shown in Code Snippet 1.

Code Snippet 1

& lt ; system.serviceModel & gt ;

& lt ; services & gt ;

& lt ; service name= ” TestServices.NewService ”

behaviorConfiguration= ” TestServices.NewService ” & gt ;

& lt ; endpoint address= ” ” binding= ” wsHttpBinding ”

contract= ” TestServices.NewService.INewService ” & gt ;

& lt ; individuality & gt ;

& lt ; dns value= ” localhost ” / & gt ;

& lt ; /identity & gt ;

& lt ; /endpoint & gt ;

& lt ; endpoint address= ” mex ” binding= ” mexHttpBinding ” contract= ” IMetadataExchange ” / & gt ;

& lt ; /service & gt ;

& lt ; /services & gt ;

& lt ; behaviours & gt ;

& lt ; serviceBehaviors & gt ;

& lt ; behavior name= ” TestServices.NewServiceBehavior ” & gt ;

& lt ; serviceMetadata httpGetEnabled= ” true ” / & gt ;

& lt ; serviceDebug includeExceptionDetailInFaults= ” false ” / & gt ;

& lt ; /behavior & gt ;

& lt ; /serviceBehaviors & gt ;

& lt ; /behaviors & gt ;

& lt ; /system.serviceModel & gt ;

2. Implement the service contract. To implement the service, you start by specifying the contract via the interface. For illustration, see a scenario where you want to expose methods of a service that work with the Suppliers table in a Shipments database. Make a Supplier category inside ISupplierService.cs and tag it as a DataContract and taging each of its members as DataMember. Code Snippet 2 shows an illustration:

Code Snippet 2

[ DataContract ]

public category Supplier

{

// specify a belongings

[ DataMember ]

public int SupplierCode { get ; set ; }

// define other belongingss

}

The following measure is to specify the methods of your interface in ISupplierService.cs and tag them with the OperationContract property. You need to tag the interface with the ServiceContract property 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 utilize 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 category SupplierService: ISupplierService

{

confString =

ConfigurationManager.ConnectionStrings [ “ SupplierString ” ] .ToString ( ) ;

public Supplier GetSupplier ( int supplierId )

{

. . .

}

public nothingness Display ( Supplier provider )

{

. . .

}

}

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

5.3.2 Calling or devouring the WCF service

The stairss to configure one or more service end points and host the service in an application are taken attention of by default while executing all the stairss carried out until now. For illustration, an end point is configured via the default HTTP end point set up inside the web.config file and the service is hosted by IIS and ASP.NET.

Now eventually, you can name the WCF service. You need to put a client to name 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 traveling to be an ASP.NET Web site for the current scenario, the stairss to name the service are as follows:

1. Make an ASP.NET Web site.

2. To bring forth a proxy category utilizing Ocular Studio 2008, right-click your Web site and choice Add Service Reference. The Add Service Reference duologue box is displayed as shown in figure 5.2.

This duologue box allows you to specify an reference to your service. The construct of proxy category is similar to that in XML Web services – it is a WCF service client enabling you to work with the service without holding to cover with the inside informations of WCF. You can besides make the placeholder by utilizing the ServiceModel Metadata Utility command-line tool ( Svcutil.exe ) .

3. Stipulate an appropriate namespace in the Namespace box in the duologue box. This namespace will specify the name for the proxy category that will be generated by Ocular Studio.

4. Specify binding and end point information. Actually, the Add ServiceReference duologue box generates the appropriate end point information automatically when you add the service mention. The web.config file will incorporate this information as shown in Code Snippet 5.

Code Snippet 5

& lt ; system.serviceModel & gt ;

& lt ; bindings & gt ;

& lt ; wsHttpBinding & gt ;

& lt ; adhering 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 ” & gt ;

& lt ; readerQuotas maxDepth= ” 32 ” maxStringContentLength= ” 8192 ”

maxArrayLength= ” 16384 ” maxBytesPerRead= ” 4096 ”

maxNameTableCharCount= ” 16384 ” / & gt ;

& lt ; reliableSession ordered= ” true ” inactivityTimeout= ” 00:10:00 ”

enabled= ” false ” / & gt ;

& lt ; security mode= ” Message ” & gt ;

& lt ; transport clientCredentialType= ” Windows ” proxyCredentialType= ” None ”

realm= ” ” / & gt ;

& lt ; message clientCredentialType= ” Windows ” negotiateServiceCredential= ” true ”

algorithmSuite= ” Default ” establishSecurityContext= ” true ” / & gt ;

& lt ; /security & gt ;

& lt ; /binding & gt ;

& lt ; /wsHttpBinding & gt ;

& lt ; /bindings & gt ;

& lt ; client & gt ;

& lt ; endpoint address= ” hypertext transfer protocol: //localhost:4392/SupplierService.svc ”

binding= ” wsHttpBinding ”

bindingConfiguration= ” WSHttpBinding_ISupplierService ”

contract= ” NwServices.ISupplierService ”

name= ” WSHttpBinding_ISupplierService ” & gt ;

& lt ; individuality & gt ;

& lt ; dns value= ” localhost ” / & gt ;

& lt ; /identity & gt ;

& lt ; /endpoint & gt ;

& lt ; /client & gt ;

& lt ; /system.serviceModel & gt ;

There are two options to pull off and redact the WCF constellation information: you can redact straight in web.config or you can utilize the Service Configuration Editor to pull off your end points. Right-click the web.config file and take Edit Wcf Configuration. This will establish the Service Configuration Editor duologue box.

Finally, you will make a Web page will name the service via the proxy category. Code Snippet 6 shows portion of the codification in the Web page that will instantiate the proxy category and name the service.

Code Snippet 6

. . .

SupplierServices.SupplierServiceClient testSupplier =

new SupplierServices.ShipperServiceClient ( ) ;

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

provider = testSupplier.GetSupplier ( supplierCode ) ;

5.5 New Data Controls in ASP.NET 3.5

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

5.5.1 LinqDataSource

Language-Integrated Query ( LINQ ) is a set of characteristics that adds question capablenesss to.NET linguistic communications such as C # . LINQ enables you to question informations from diverse informations beginnings in an easy mode. The lone status is that these informations beginnings 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 aggregations ) , and ADO.NET DataSets.

The LinqDataSource is new to ASP.NET 3.5 and Visual Studio 2008. It is used to recover informations from a LINQ information theoretical account. This control enables you to expose informations from a database by utilizing LINQ to SQL. Once you have generated informations categories utilizing the Object/Relational ( O/R ) interior decorator, you can adhere to those categories utilizing the LinqDataSource control.

The ContextTypeName property is used in markup with the LinqDataSource to tie in the database context of your LINQ-based informations.

See a scenario where you have defined a DataContext category named EmpDataContext utilizing Linq to SQL Classes in Visual Studio 2008. The following markup shows how you would link to this category utilizing the LinqDataSource control:

Code Snippet 7

& lt ; asp: LinqDataSource

ID= ” lnqEmp ”

runat= ” waiter ”

ContextTypeName= ” EmpDataContext ”

EnableDelete= ” True ”

EnableInsert= ” True ”

EnableUpdate= ” True ”

OrderBy= ” EmpCode ”

TableName= ” Employees ” & gt ;

& lt ; /asp: LinqDataSource & gt ;

Alternatively of typing the markup shown in Code Snippet 7, you can besides utilize the Configure Data Source ace to tie in the DataContext category with the LinqDataSource control. This can be done utilizing following stairss:

1. Add a LinqDataSource control to the Web page.

2. Snap the smart ticket beside the control.

3. In the context bill of fare that is displayed, choice Configure Data Source. This will expose the Configure Data Source ace as shown in figure 5.3.

Figure 5.3: Configure Data Source Wizard for LinqDataSource

4. Continue with the measure by measure process shown in the Configure Data Source ace.

The LinqDataSource control allows you to specify parametric quantities, to bespeak sorting, enable paging, and more. You can besides specify questions holding Where and OrderBy clauses. The Where clause uses the WhereParameters stand foring a question twine that filters the information on the question twine. You can besides adhere 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 entree informations utilizing the ADO.NET Entity Framework. Users who are familiar with data-bound controls will happen the EntityDataSource control similar to the SqlDataSource, LinqDataSource, and ObjectDataSource controls. The EntityDataSource control enables you to adhere informations in an Entity Data Model ( EDM ) to Web controls on a page. You construct questions utilizing snippings of Entity SQL codification and delegate them to the Where, OrderBy, GroupBy, and Select operators. You can provide parameter values to these operations from page controls, cookies, and other ASP.NET parametric quantity objects. The EntityDataSource interior decorator enables you to configure an EntityDataSource control easy at design clip.

Similar to LinqDataSource, you can utilize the Configure Data Source ace of the EntityDataSource control to initialise the informations beginning. Figure 5.4 shows the ace.

Initially, the ace enables you to choose a named connexion from the Web.Config file or add a connexion twine to link to the database. The 2nd page of the ace will hold content depending on whether a Select statement configured by the options on the ace is used or some other bid text is used.

5.5.3 ListView

The ListView control is used to adhere and expose informations points from a information beginning. The ListView provides characteristics that support folio, screening, and grouping of points. Using the ListView control, you can execute edit, insert, and delete operations on informations without the demand for any codification.

You can adhere the ListView control to informations by utilizing the DataSourceID belongings. This enables you to adhere the ListView control to a information beginning control, such as the SqlDataSource control. You can besides adhere the ListView control to informations by utilizing the DataSource belongings. This enables you to adhere to assorted objects, which includes ADO.NET datasets and informations readers and in-memory constructions such as aggregations. This attack requires that you write codifications for any extra functionality such as sorting, paging, and updating.

Items that are displayed by a ListView control are defined by templets, likewise to the DataList and Repeater controls. The ListView control lets you expose informations as single points or in groups.

You define the chief layout of a ListView control by making a LayoutTemplate templet. The LayoutTemplate must include a control that acts as a proxy for the information. You define content for single points utilizing the ItemTemplate templet. This templet typically contains controls that are data-bound to data columns or other single informations elements.

Code Snippet 8 shows a ListView control that displays names of classs from the Categories tabular array in Library database.

Code Snippet 8

& lt ; caput runat= ” waiter ” & gt ;

& lt ; title & gt ; ListView Demo & lt ; /title & gt ;

& lt ; manner type= ” text/css ” & gt ;

.table

{

boundary line: thin # 000000 solid ;

border-collapse: prostration ;

boundary line: 1px solid # 000000 ;

}

table td

{

boundary line: 1px solid # FF0000 ;

}

& lt ; /style & gt ;

& lt ; /head & gt ;

& lt ; organic structure & gt ;

& lt ; signifier id= ” form1 ” runat= ” waiter ” & gt ;

& lt ; div & gt ;

& lt ; /div & gt ;

& lt ; br / & gt ;

& lt ; br / & gt ;

& lt ; asp: ListView runat= ” waiter ” ID= ” ListView1 ” DataSourceID= ” SqlDataSource1 ” & gt ;

& lt ; LayoutTemplate & gt ;

& lt ; table runat= ” waiter ” id= ” table1 ” class= ” tabular array ” & gt ;

& lt ; tr runat= ” waiter ” id= ” itemPlaceholder ” & gt ;

& lt ; /tr & gt ;

& lt ; /table & gt ;

& lt ; /LayoutTemplate & gt ;

& lt ; ItemTemplate & gt ;

& lt ; tr id= ” Tr1 ” runat= ” waiter ” & gt ;

& lt ; td id= ” Td1 ” runat= ” waiter ” & gt ;

& lt ; % — Data-bound content. — % & gt ;

& lt ; asp: Label ID= ” NameLabel ” runat= ” waiter ” Text= ‘ & lt ; % # Eval ( “ Category ” ) % & gt ; ‘ / & gt ;

& lt ; /td & gt ;

& lt ; /tr & gt ;

& lt ; /ItemTemplate & gt ;

& lt ; /asp: ListView & gt ;

& lt ; asp: SqlDataSource ID= ” SqlDataSource1 ” runat= ” waiter ” ConnectionString= ” & lt ; % $ ConnectionStrings: LibraryConnectionString % & gt ; ”

SelectCommand= ” SELECT [ CategoryID ] , [ Category ] FROM [ BookCategories ] ” & gt ; & lt ; /asp: SqlDataSource & gt ;

The end product of this markup is seen in figure 5.6.

5.6 Globalization

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

ASP.NET allows you to develop Web applications that can be accessed by 1000000s of users across the Earth. This means that the Web applications should be created taking into consideration the demands of users from assorted parts of the universe. Therefore, you need to internationalise your application to do it accessible to users belonging to different states, parts, civilizations, linguistic communications, and so on. Globalizationinvolves the procedure of developing Web applications that can be used by users from different parts of the universe. These Web applications will be independent of the linguistic communication and civilization.

In short, globalising an application involves doing your application readable to a broad scope of users irrespective the cultural and regional differences.

See a scenario of a medical research company in New York. The company has created a Web application that displays the consequences of different researches carried out by the company. The Web application is created sing a broad scope of users of different linguistic communications and civilizations. This means that the Web site is civilization and linguistic communication specific. Therefore, 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 stand foring the medical marks and symbols. This means that irrespective of the user ‘s location, the marks and symbols should look same. To implement this, developers can globalise the Web application.

Using ASP.NET, you can make Web applications that can automatically set civilization, and arrange day of the months and currency harmonizing to user demands.

ASP.NET supports globalisation by supplying the System.Globalization namespace. The System.Globalization namespace provides a set of categories to construct applications that can be supported across the Earth. These categories allow you to cover with assorted globalisation issues such as civilization, part, calendar support, and date-time data format. Table 5.1 lists the normally used categories of the System.Globalizationnamespace.

Class

Description

Calendar

This category represents yearss in hebdomads, months, and old ages. It is the basal category for other civilization specific calendars such as GregorianCalendar, JapaneseCalendar, and KoreanCalendar

CultureInfo

This category provides culture-specific information such as name of the civilization and linguistic communication

NumberFormatInfo

This category represents the manner the numeral values are formatted and displayed for a specific civilization

RegionInfo

This category provides information about country/region such as country/region name and two missive codification defined in ISO 3166

Table 5.1: Normally Used Classs of System.Globalization

For illustration, to expose the currency symbol of the current civilization in your Web application, the codification shown in Code Snippet 9 will be used.

Code Snippet 9

CultureInfo curie = System.Threading.CurrentThread.CurrentCulture ;

NumberFormatInfo nfi = ci.NumberFormat ;

Response.Write ( “ Currency Symbol: “ + nfi.CurrencySymbol + “ & lt ; BR & gt ; ” ) ;

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

You can put the civilization or an ASP.NET Web page declaratively utilizing one of two attacks:

  • Add a globalisation subdivision to the web.config file, and so put the uiculture and civilization properties, as shown:

    & lt ; globalisation uiCulture= ” Es ” culture= ” es-MX ” / & gt ;

    This sets the UI civilization and civilization for all pages,

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

    & lt ; % @ Page UICulture= ” Es ” Culture= ” es-MX ” % & gt ;

    This sets the UI civilization and civilization for an single page,

  • .NET Framework 4
  • Ocular Studio 2005

    A resource file is used to hive away user interface strings for interpreting the application into other linguistic communications. It is a utile constituent in the procedure of globalisation and localisation. Resource files are stored in XML format and contain strings, image file waies, and other resources. This is because you can make a separate resource file for each linguistic communication into which you want to interpret a Web page.

    The stairss to make a resource file are as follows:

    1. Ensure that your Web site has a booklet such as App_GlobalResources in which to hive away the resource file. You can add such a booklet by right-clicking on the Website name in Solution Explorer and choosing Add ASP.NET Folder and so choosing App_GlobalResources as shown in figure 5.7.
    2. Right-click the App_GlobalResources booklet, and so snap Add New Item. This will make a resource file,
    3. In the Add New Item duologue box, under Ocular Studio installed templets, click Resource File.
    4. In the Name box, stipulate a name for the resource file and so snap Add. The Resources Editor window glass is displayed where you can type names ( keys ) , values, and optional remarks bespeaking each resource point.
    5. Type appropriate key names and values for each resource that you need in your application, and so salvage the file.
    6. To make resource files for extra linguistic communications, copy the file in Solution Explorer or in Windows Explorer, and so rename it utilizing the syntax filename.language-culture.resx. For case, if you create a planetary resource file named Resources.resx for interlingual rendition to Spanish ( Mexico ) , you will call the copied file Resources.es-mex.resx. Open the copied file and interpret each value, go forthing the names ( keys ) the same.
    7. Perform and reiterate stairss 6 and 7 for each extra linguistic communication that you want to utilize.

    5.8 Accessibility Support in ASP.NET

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

    Accessible Web applications enable people with disablements to utilize assistive engineerings, such as screen readers, to work with Web pages. ASP.NET can assist you make accessible Web applications.

    ASP.NET controls support handiness criterions including Web Content Accessibility Guidelines 1.0 ( WCAG ) to a great extent. However, sometimes ASP.NET controls produce consequences that fail to follow with all handiness criterions. In such instances, you will necessitate to manually configure the controls for handiness.

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

    • Set check order for controls utilizing the TabIndex belongings.
    • Stipulate a default button for a signifier or Panel control by puting the DefaultButton belongings.
    • Define entree keys for button controls by puting the AccessKey belongings.
    • Use Label controls with text boxes, which let you specify entree keys for the text boxes.

    5.9 Mobile Applications in ASP.NET 3.5

    Today, in major parts of the universe, a nomadic phone is no longer a luxury but a necessity. Mobile devices such as smartphones, Personal Digital Assistants ( PDAs ) , and others have become indispensable appliances and back up many powerful characteristics that make life easier and well-organized. These nomadic devices can hold a figure of applications installed on them. Mobile application development is hence considered to be a important portion of a developer ‘s skillset. As an ASP.NET developer, it is imperative for you to be familiar with the creative activity of both Web and nomadic applications.

    5.9.1 Mobile Application Creation in ASP.NET 3.5

    In earlier versions of Ocular Studio before Visual Studio 2008, there was built-in interior decorator support for developing nomadic Web applications. The IDE provided an application templet utilizing which you could make a new nomadic Web application. An point templet allowed you to custom-make the show and visual aspect of controls in Design View. Using the interior decorator, you could work with nomadic Web signifiers and nomadic Web user controls in Design View. The IDE besides provided tool chest and design-time layout support which made the undertaking of working with ASP.NET Mobile Web applications simple and easy.

    However, from Ocular Studio 2008 onwards, there is no reinforced -in interior decorator support for developing nomadic Web applications. You can still make and work with nomadic Web applications by utilizing downloaded templets from the Web. The stairss to make this are listed below:

    1. Download ASP.NET Mobile Templates.zip from hypertext transfer protocol: //blogs.msdn.com/b/webdevtools/archive/2007/09/17/tip-trick-asp-net-mobile-development-with-visual-studio-2008.aspx
    2. Extract the nothing file. This will ensue in a figure of other nothing files.
    3. Copy the nothing files with file names stoping with “ _cs ” to: [ My Documents ] Visual Studio 2008TemplatesItemTemplatesVisual C # .
    4. Restart Visual Studio.
    5. Create an empty Website as shown in Figure 5.8.
    6. Select WebsiteaAdd New Item. The Add New Item duologue box will expose the freshly added templates available as shown in figure 5.9.
    7. Choose the templet Mobile Web Form as shown in figure 5.10 and click Add.

    A nomadic Web signifier will be added to the Website application.

    Switch to the codification position. You will detect that the Default category inherits from System.Web.UI.MobileControls.MobilePage.

    An alternate manner of making Mobile Web signifiers in Ocular Studio 2008 is to add a Web signifier to your application and so modify the page category declaration to inherit from System.Web.UI.MobileControls.MobilePage.

    Once the Mobile Web page is created utilizing either of these two attacks, you can so put nomadic Web controls onto the page by dragging them from the Toolbox or by typing markup and properties.

    Code Snippet 10 demonstrates how to make a simple nomadic signifier with a Panel and a Label control.

    Code Snippet 10

    & lt ; % @ Page Language= ” C # ” AutoEventWireup= ” true ” CodeFile= ” Default.aspx.cs ” Inherits= ” _Default ” % & gt ;

    & lt ; % @ Register TagPrefix= ” Mobile ” Namespace= ” System.Web.UI.MobileControls ” Assembly= ” System.Web.Mobile ” % & gt ;

    & lt ; html xmlns= ” hypertext transfer protocol: //www.w3.org/1999/xhtml ” & gt ;

    & lt ; organic structure & gt ;

    & lt ; nomadic: Form id= ” Form1 ” runat= ” waiter ” BackColor= ” # 99ffcc ” & gt ;

    & lt ; Mobile: Label Name= ” lblMessage ” runat= ” waiter ” Font-Bold= ” True ” ForeColor= ” Blue ”

    Font-Size= ” Large ” & gt ; Welcome, this is exciting & lt ; /mobile: Label & gt ;

    & lt ; br & gt ; & lt ; /br & gt ;

    & lt ; Mobile: Image ID= ” Image1 ” Runat= ” waiter ” ImageUrl= ” Garden.jpg ” & gt ;

    & lt ; /mobile: Image & gt ;

    & lt ; /mobile: Form & gt ;

    & lt ; /body & gt ;

    & lt ; /html & gt ;

    Save and construct the application.

    5.9.2 Executing Mobile Applications

    The stairss to prove this application are as follows:

    1. Install the Windows Mobile Device Center if it is non already installed.
    2. Install Windows Mobile 6.0 Professional SDK Refresh if it is non already installed.
    3. Select Tools- & gt ; Device Emulator Manager in the Visual Studio 2008 IDE.
    4. Right-click Windows Mobile 6.0 Professional Emulator in the Device Emulator Manager duologue box and choice Connect.
    5. Right-click Windows Mobile 6.0 Professional Emulator in the Device Emulator Manager duologue box and choice Cradle. Windows Mobile Device Center ( WMDC ) is opened. Ensure that the connexion puting on WMDC is set to DMA. If you are utilizing a Work web to link to the Internet, so choose “ This computing machine connects to Work Network. ”
    6. Launch Internet Explorer on the copycat and navigate to the URL of your nomadic Web application. Assuming that the local machine name is test, the end product will be as shown in figure 5.11. You can besides utilize the IP reference of the machine alternatively of machine name.

    5.9.3 Mobile Device Capabilities

    Peoples around the universe usage different nomadic devices. These devices may differ in show sizes and capablenesss. If a Web developer develops a Web application for a specific nomadic device, it may non work when exported to other nomadic devices. To get the better of this job, there is a demand of some agencies of device filtering. Device filtering is the procedure of custom-making nomadic Web waiter controls to correctly expose them on select nomadic devices.

    Using device filters, nomadic Web applications can custom-make the visual aspect of controls for specific hardware devices. The customization is based on the capablenesss of the hardware device being used to shop the application. Device filters are used to custom-make the behaviour of Web waiter controls depending on the browser or device that accesses them.

    Typically, the web.config file shops device capablenesss in the & lt ; deviceFilters & gt ; subdivision.

    By default, your nomadic Web application in.NET Framework 3.5 and Visual Studio 2008 may non hold a web.config file. To add it, launch the Add New Item duologue box and choose the Mobile Web Configuration point templet as shown in figure 5.12.

    The web.config will incorporate undermentioned device filters by default in the & lt ; deviceFilters & gt ; subdivision:

    & lt ; deviceFilters & gt ;

    & lt ; filter name= ” isJPhone ” compare= ” Type ” argument= ” J-Phone ” / & gt ;

    & lt ; filter name= ” isHTML32 ” compare= ” PreferredRenderingType ”

    argument= ” html32 ” / & gt ;

    & lt ; filter name= ” isWML11 ” compare= ” PreferredRenderingType ” argument= ” wml11 ”

    / & gt ;

    & lt ; filter name= ” isCHTML10 ” compare= ” PreferredRenderingType ”

    argument= ” chtml10 ” / & gt ;

    & lt ; filter name= ” isGoAmerica ” compare= ” Browser ” argument= ” Go.Web ” / & gt ;

    & lt ; filter name= ” isMME ” compare= ” Browser ” argument= ” Microsoft Mobile

    Explorer ” / & gt ;

    & lt ; filter name= ” isMyPalm ” compare= ” Browser ” argument= ” MyPalm ” / & gt ;

    & lt ; filter name= ” isPocketIE ” compare= ” Browser ” argument= ” Pocket IE ” / & gt ;

    & lt ; filter name= ” isUP3x ” compare= ” Type ” argument= ” Phone.com 3.x Browser ” / & gt ;

    & lt ; filter name= ” isUP4x ” compare= ” Type ” argument= ” Phone.com 4.x Browser ” / & gt ;

    & lt ; filter name= ” isEricssonR380 ” compare= ” Type ” argument= ” Ericsson R380 ” / & gt ;

    & lt ; filter name= ” isNokia7110 ” compare= ” Type ” argument= ” Nokia 7110 ” / & gt ;

    & lt ; filter name= ” prefersGIF ” compare= ” PreferredImageMIME ”

    argument= ” image/gif ” / & gt ;

    & lt ; filter name= ” prefersWBMP ” compare= ” PreferredImageMIME ”

    argument= ” image/vnd.wap.wbmp ” / & gt ;

    & lt ; filter name= ” supportsColor ” compare= ” IsColor ” argument= ” true ” / & gt ;

    & lt ; filter name= ” supportsCookies ” compare= ” Cookies ” argument= ” true ” / & gt ;

    & lt ; filter name= ” supportsJavaScript ” compare= ” Javascript ” argument= ” true ” / & gt ;

    & lt ; filter name= ” supportsVoiceCalls ” compare= ” CanInitiateVoiceCall ” argument= ” true ” / & gt ;

    & lt ; /deviceFilters & gt ;

    ASP.NET provides the HasCapability ( ) method in the MobileCapabilities category to find device capablenesss for nomadic devices. The method takes two parametric quantities. The first is a twine stipulating a delegateName that will indicate to the device rating method, belongings name, or so forth and the 2nd parametric quantity is any value that the capabilityName statement requires. The 2nd parametric quantity is optional.

    The HasCapability ( ) method enables you to find through codification whether the current device lucifers any device filter specified in the web.config file.

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

    Code Snippet 11:

    attempt

    {

    bool consequence = ( ( MobileCapabilities ) Request.Browser ) .HasCapability ( “ supportsColor ” , null ) ;

    txtvwMessage.Text = answer.ToString ( ) ;

    }

    gimmick ( ArgumentOutOfRangeException )

    {

    txtvwMessage.Text = “ false ” ;

    }

    Here, the codification tries to look into 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 result of Code Snippet 11 is that the TextView shows true.

    5.9.4 Using the DeviceSpecific Control

    The procedure of rendering a control otherwise based on the browser that requested the Web page is called adaptative rendition. You use the DeviceSpecific component in ASP.NET Mobile applications to implement adaptative rendition.

    One or more & lt ; Choice & gt ; elements incorporating different versions of the content aiming different devices are placed inside the & lt ; DeviceSpecific & gt ; component, as shown in Code Snippet 12.

    Code Snippet 12

    & lt ; nomadic: Form id= ” frmTest ” runat= ” waiter ” & gt ;

    & lt ; Mobile: Label Runat= ” waiter ” ID= ” Label1 ” & gt ;

    Welcome

    & lt ; DeviceSpecific & gt ;

    & lt ; Choice Filter= ” isPocketIE ” Font-Italic= ” True ” Font-Name= ” Arial

    Black ” / & gt ;

    & lt ; Choice Filter= ” isNokia7110 ” ForeColor= ” Magenta ” / & gt ;

    & lt ; /DeviceSpecific & gt ;

    & lt ; /mobile: Label & gt ;

    & lt ; /mobile: Form & gt ;

    Choices are evaluated from the first & lt ; Choice & gt ; component to the last. Each pick includes a Filter component. If the device satisfies the Filter so the content within that pick is displayed to the client. The last pick in the above illustration has no Filter. The content in this pick shows on all of the devices that satisfy none of the filters.

    The Filter property of the & lt ; Choice & gt ; component can besides mention to a filter in the web.config file.

    Drumhead

    • WCF is a incorporate scheduling theoretical account that helps to make distributed applications utilizing.NET engineerings.
    • ASP.NET 3.5 defines several new informations related controls including LinqDataSource, EntityDataSource, and ListView.
    • Globalization involves the procedure of developing Web applications that can be used by users from different parts of the universe.
    • A resource file is used to hive away user interface strings for interpreting the application into other linguistic communications and plays an of import function in globalisation.
    • Most ASP.NET controls provide constitutional support for handiness in Web applications.
    • ASP.NET 3.5 enables you to develop nomadic Web applications.
    • Mobile device capablenesss differ from device to device and are specified utilizing & lt ; deviceFilters & gt ; in web.config file.