How to work with XBAP in Windows Azure

Article translations Article translations
Article ID: 2425647 - View products that this article applies to.
Expand all | Collapse all

On This Page

INTRODUCTION

This article describes an All-In-One Code Framework sample that is available for download.
The code sample demonstrates the following typical scenario:
  • You host a web service in the cloud.
  • You distribute a client application from the cloud.
  • You consume the cloud service from the client application.

In the code sample, the client application is an XAML Browser Application (XBAP), and the cloud service is a Windows Communication Foundation (WCF) service hosted in a Windows Azure Web Role.

Difficulty level

Collapse this imageExpand this image
codefx Medium

Download information

To download this code sample, click the following link:

    


Technical overview

Distribute XBAP from Windows Azure

To distribute a XBAP from Windows Azure, use the following steps:
  1. Create a Windows Azure solution with at least one Web Role project.
  2. Create a new (or include an existing) XBAP project in the same solution.
  3. Build the solution.
  4. Right click the Web Role project, choose Add existing item, navigate to the output directory of the XBAP application, and add the following files to the Web Role project:
    File 1
    <file name>.exe
    File 2
    <file name>.exe.manifest
    File 3
    <file name>.xbap
  5. Select the above files, and set their Build Action to Content.
  6. If you want to display the XBAP application when the user navigates to the root URI of your Web Role, please modify web.config, and add the following under the system.webServer section (replace XbapClient.xbap to your XBAP's name):
        <defaultDocument>
          <files>
            <clear/>
            <add value="XbapClient.xbap"/>
          </files>
        </defaultDocument>
    
Run the solution in Development Fabric, and you should be able to see the XBAP application. It also works fine after deployed to the real cloud.

Note If you want to modify the original XBAP project, you must take additional steps for the changes to be reflected in the Web Role:
  1. Open a Visual Studio command prompt, and run the following command to clear the XBAP cache:
    mage -cc
  2. Delete the .exe, .manifest, and .xbap files from the Web Role.
  3. Repeat step 3 to step 5 above.
Because an XBAP project cannot be associated to a Web Role project automatically, you have a lot of manual tasks to do whenever you want to update the XBAP project. You can try to create a Visual Studio script to automate the process, but if a Silverlight project meets your requirement, you should definitely use Silverlight.

Access web services from XBAP

In most cases, to provide a true connected experience, the client applications that are distributed from the cloud need to invoke web services hosted in the cloud, This sample demonstrates how to access a WCF SOAP service from XBAP.
The process is similar to accessing an SOAP service from a normal client. If you need to allow clients to add a service reference to your Windows Azure WCF service, you need the hotfix and workaround by visiting the following web site:
971842 FIX: URIs in a WCF WSDL document refer to inaccessible internal instances instead of to the load balancer as expected in the .NET Framework 3.0 in Windows Server 2003, Windows XP, Windows Vista and Windows Server 2008

However, there are also a few unique tasks to perform in order to make WCF calls successful in XBAP:
  • You must configure the service endpoint in code rather than in app.config. By default, in Windows Azure (and normal IIS environment), an <file name>.config file (such as web.config and app.config) is not allowed to be downloaded to the client. You can configure system.webServer to allow the download, but that makes web.config to be downloadable as well, which may cause serious security concerns. Therefore it is always recommended to take the code only approach for XBAP applications. Silverlight applications do not have this problem, because the configuration file name's extension is ClientConfig, rather than config.
  • After adding the service reference, you need to remove the generated app.config file.
  • To configure the service endpoint in code, you can use the following overload of the client proxy class:
    public DataCenterServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress)

    This overload requires the service address information. You can use an absolute address. But if the service is hosted in the same Web Role, it is recommended to use a relative URI, so you don't need to modify the code before deploying the application to the cloud. The relative URI can be obtained with the help of BrowserInteropHelper.Source property:
    Uri serviceUri = new Uri(BrowserInteropHelper.Source, "../DataCenterService.svc");
  • A partial trust XBAP can only consume services from the same domain by default. To invoke cross domain services, you must modify the application properties to use full trust, or grant yourself permission to access web resources. Silverlight cross domain access policy file does not affect XBAP. Note if your XBAP is not use the default partial trust configuration, you must make sure it does not perform any tasks that may harm the end user's machine, and you must sign the XBAP with a valid certificate, otherwise you won't be able to deploy a non-default partial trust XBAP to an internet environment, such as the cloud. This sample does not cover the non-default partial trust scenario.

Technology category

  • Windows Azure
  • XBAP
  • WPF

Languages

This code sample contains the following programming languages:

Collapse this tableExpand this table
LanguageProject Name
Visual C#CSAzureXbap
Visual Basic.NETVBAzureXbap

Prerequisites

  • This sample application was created by using Visual Studio 2010 with Windows Azure Tools for Microsoft Visual Studio 1.2.

Tags

  • Windows Azure
  • XBAP
  • WPF
  • Multi-touch
  • 3D
  • WCF

MORE INFORMATION

What is All-In-One Code Framework?

All-In-One Code Framework shows most Microsoft development techniques by using code samples in different programming languages. Each example is carefully selected, composed, and documented to show one common code scenario. For more information about All-In-One Code Framework, visit the following Web site:

http://1code.codeplex.com

How to find more All-In-One Code Framework samples

To find more All-In-One Code Framework samples, you can simply click the following link:

http://support.microsoft.com/gp/gp_kbcodefx
Rapid publishing disclaimer
Microsoft corporation and/or its respective suppliers make no representations about the suitability, reliability, or accuracy of the information and related graphics contained herein. All such information and related graphics are provided "as is" without warranty of any kind. Microsoft and/or its respective suppliers hereby disclaim all warranties and conditions with regard to this information and related graphics, including all implied warranties and conditions of merchantability, fitness for a particular purpose, workmanlike effort, title and non-infringement. You specifically agree that in no event shall Microsoft and/or its suppliers be liable for any direct, indirect, punitive, incidental, special, consequential damages or any damages whatsoever including, without limitation, damages for loss of use, data or profits, arising out of or in any way connected with the use of or inability to use the information and related graphics contained herein, whether based on contract, tort, negligence, strict liability or otherwise, even if Microsoft or any of its suppliers has been advised of the possibility of damages.


Properties

Article ID: 2425647 - Last Review: November 17, 2010 - Revision: 6.0
APPLIES TO
  • Windows Azure
Keywords: 
kbcodefx kbinfo kbsurveynew kbnomt atdownload kbrapidpub KB2425647

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com