This article describes an All-In-One Code Framework sample that is available for download.
The code sample demonstrates the following typical scenario:
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 Microsoft Azure Web Role.
Difficulty level
Distribute XBAP from Microsoft Azure
To distribute a XBAP from Microsoft Azure, use the following steps:
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:
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 Microsoft Azure WCF service, you need the hotfix and workaround by visiting the following web site:
However, there are also a few unique tasks to perform in order to make WCF calls successful in XBAP:
Tags
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 Microsoft Azure Web Role.
Difficulty level
Download information
To download this code sample, click the following link:Technical overview
Distribute XBAP from Microsoft Azure
To distribute a XBAP from Microsoft Azure, use the following steps:- Create a Microsoft Azure solution with at least one Web Role project.
- Create a new (or include an existing) XBAP project in the same solution.
- Build the solution.
- 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 - Select the above files, and set their Build Action to Content.
- 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>
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:
- Open a Visual Studio command prompt, and run the following command to clear the XBAP cache:
mage -cc
- Delete the .exe, .manifest, and .xbap files from the Web Role.
- Repeat step 3 to step 5 above.
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 Microsoft 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 Microsoft 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
- Microsoft Azure
- XBAP
- WPF
Languages
This code sample contains the following programming languages:Language | Project Name |
Visual C# | CSAzureXbap |
Visual Basic.NET | VBAzureXbap |
Prerequisites
- This sample application was created by using Visual Studio 2010 with Microsoft Azure Tools for Microsoft Visual Studio 1.2.
Tags
- Microsoft Azure
- XBAP
- WPF
- Multi-touch
- 3D
- WCF