2 out of 3 rated this helpful - Rate this topic

Guidance for Using WCF in Windows Azure

Updated: February 6, 2012

The Windows Communication Foundation (WCF) is a framework for building service-oriented applications. This topic provides general guidance on using WCF in Windows Azure. For more information about the fundamentals of WCF, see Fundamental Windows Communication Foundation Concepts.

This topic covers the following concepts:

WCF services can be hosted in either a web role or a worker role. Which type of role you decide to use depends on the type of WCF service you are writing.

Web roles are customized for web application programming as supported by IIS 7 and ASP.NET. When you use a web role Windows Azure completes the basic IIS setup for you. This role is best used for providing a web-based front end for your hosted service. Web roles in Windows Azure provide support for the HTTP and HTTPS protocols and can serve applications that use the HTTP protocol with a WCF service by using the basicHttpBinding element of the WCF service model.

Worker roles are useful for generalized development, and can perform background processing for a web role. When you have a need for a background process that performs long-running or intermittent tasks, you should use a worker role. External endpoints enable worker roles to expose Internet-facing services over ports other than 80 and 443. These endpoints can be bound to any process and allow the process to communicate externally using a variety of TCP-based application protocols with the WCF service by using the netTcpBindings binding.

The netTcpBindings binding can also be used to communicate internally with a WCF service hosted in a worker role. A scenario in which this is useful is a hosted service that consists of an ASP.Net/MVC site that is running in a web role that communicates with a WCF service that is running in a worker role.

A WCF service that is set up for deployment to a Windows Azure web role uses the same setup and configuration as a WCF service hosted in IIS on on-premise servers. The tips described in this section will help you make the transition to Windows Azure smoothly.

Many HTTP applications, notably WCF, assume that the VIP and dip port are set to the same value.  For example, when WCF produces MEX/WSDL documents (to support the Visual Studio Add Service Reference function), it uses the current request to build various absolute URIs. The ports must match to enable Visual Studio to generate the correct references. When you configure the service definition for the hosted service you should configure the input endpoint to specify that both the port attribute and localPort attribute are set to 80 as shown in the following code snippet.


<ServiceDefinition name="MyService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
   <WebRole name="WebRole1">
      …
      <Endpoints>
         <InputEndpoint name="HttpIn" protocol="http" port="80" localPort="80" />
      </Endpoints>
   </WebRole>
   …
</ServiceDefinition>

noteNote
If you are using the .NET Framework 3.5 make sure that the useRequestHeadersForMetadataAddress behavior is set in the WCF service configuration. This will make sure that the metadata and other URIs exposed in the WSDL file do not contain the host names of any internal machines. By default the .NET Framework 4 sets this behavior.

The Windows Azure Tools for Microsoft Visual Studio provides a template for creating a basic WCF service in a web role. The template configures the WCF service and the necessary Windows Azure service definitions. The example in Code Quick Start: Create and deploy a WCF service in Windows Azure shows you how to create the basic service and generate the client proxy using the Visual Studio tools.

The security concerns for hosting a WCF service on Windows Azure is the same as those you encounter hosting the service in on-premise servers. For information about security for WCF, see Security Overview in the Windows Communication Foundation documentation.

If you create a WCF service that uses SSL certificates you may encounter a failure in which the certificate cannot be verified against a trusted certification authority. When you view the certificate you see the following error:

Certificate manager certficate chain error.

This error it is typically caused by missing certificates in the certificate chain. This error can be corrected by adding all the certificates in the chain to the web role.

  1. Open your WCF solution in Visual Studio.

  2. Open the roles folder in your solution.

  3. Right click the WCF web role.

  4. Click Properties.

  5. Click the Certificate tab on the role properties pane.

  6. Add each certificate in the chain by clicking Add Certificate.

  7. Save the solution.

When you package and deploy the hosted service, the certificates are also deployed.

Use the Windows Azure Access Control Service (ACS)

You can use the Windows Azure Access Control Service (ACS) to help secure the WCF Services. See the following topics for more information:

You can troubleshoot performance issues for WCF services in Windows Azure using the same techniques that you use with WCF services hosted on-premise servers. Depending on type of issues you encounter, you may use traces and tools such as:

For information about known issues related to developing WCF clients and services, see WCF Troubleshooting quick start.

Typically WCF tracing is the best way to troubleshoot or debug any WCF issues. The following topics provide guidance about how to use WCF tracing.

  • WCF Tracing in Windows Azure SDK 1.3 or higher – This blog entry shows how to modify the web.config file to enable WCF tracing in Windows Azure.

  • Configuring Tracing – This topic describes how you can enable tracing, configure trace sources to emit traces and set trace levels, set activity tracing and propagation to support end-to-end trace correlation, and set trace listeners to access traces.

  • Using Tracing to Troubleshoot your Application – This topic lists various topics that describe how you can use tracing to troubleshoot your application.

  • Debugging WCF Services – This topic provides information about restrictions on debugging WCF, debugger support for stepping into a WCF Service, and how to debug a WCF Service that runs outside IIS or the ASP.NET Development server.

The following MSDN topics give basic guidance about how to create Windows Azure hosted service that use WCF.

The following hands-on labs are included with the Windows Azure Training Kit. The lab documents are included in htm format (.htm). Please install the prerequisites and follow the setup procedures that are described in each lab manual before you start to work through a hands-on lab.

  • Worker Role Communication

    In this hands-on lab, you will explore internal and external endpoints by implementing a WCF chat service and hosting it in a Windows Azure worker role.

  • Web Services and Identity in Windows Azure

    This lab is a step by step guide that will help you use claims-based identity for handling authentication and access management for your WCF services hosted in Windows Azure. The lab shows how you can still take advantage of local identities for authenticating the users. The lab will help you with all the practicalities of taking advantage of the unique characteristics of the Windows Azure environment from the Windows Identity Foundation settings.

  • Windows Phone 7 And The Cloud

    This hands-on lab introduces you to the tools and the steps that are required to build a small Silverlight Windows Phone 7 application that consumes a WCF Data Services from an application hosted in Windows Azure.

  • Connecting Applications through the Windows Azure Service Bus

    This lab covers the basics of the Windows Azure Service Bus. It shows how to connect clients and services via SOAP and REST over the Service Bus using the Windows Azure Libraries for .NET. It explores how to enable service automatic activation by connecting a WCF service in IIS 7.5 to the Service Bus. Additionally, it implements a multicast service to protect messages using X.509 certificates.

  • Running SOA Services with the Windows Azure HPC Scheduler

    This lab demonstrates how to create a WCF service that can run on Windows Azure compute nodes and how to create a client application that starts a WCF service job.

See Also

Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.
facebook page visit twitter rss feed newsletter