CodeKicks.com
Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Thursday, October 05, 2006

Globalization Patterns in .NET (WCF (WS-I18N implementation))

Globalization Patterns in .NET (WCF (WS-I18N implementation))

Introduction

As business becomes more global every day, there is an emerging need to make applications and services multi-lingual and culturally aware. The .NET framework already provides comprehensive support for internationalization, but it is not always clear how to apply this support to the design of services. In this article, I will describe some of the available globalization patterns for web services, and how to successfully apply them using the extensibility points provided by WCF. In addition, I will align some code samples with the recently released WCF working draft for Web Services Internationalization (WS-I18N).

Globalization Patterns

There are at least three different globalization patterns that can be applied to a WCF service during the design or development phase. These patterns are mutually exclusive; they can not be used together, so it is essential to know their differences before starting work.

  • Locale Neutral: In this pattern, most aspects of the services are not locale-affected. This is the simplest case, and additional considerations are not required. For example, a “Calculator” service that performs arithmetic operations.
  • Service Determined: Here, the service always runs in a determined locale, which can be the host’s default locale, or a locale specifically configured for that service. For example, a web service that always returns messages in English.
  • Client Influenced: In this case, the service may run in a locale provided by the client application. As the “WS-I18N” states, the service is “influenced” because it can either consider the locale in which it is running or not depending on how the service is being implemented.

These patterns do not take into account situations in which different service implementations and data contracts are used to serve clients applications in a multilingual or cross-cultural setting.

Let’s look at each of these patterns in detail.

Locale Neutral

This is the simplest case, there is no need to consider or attend to any globalization feature.

[ServiceContract(Namespace="http:
//Microsoft.ServiceModel.Samples"
)]
public interface ICalculator
{
[OperationContract]
double Add(double n1, double n2);
[OperationContract]
double Subtract(double n1, double n2);
} // Service class which implements the service contract.
public class CalculatorService : ICalculator
{
public double Add(double n1, double n2)
{
return n1 + n2;
}
public double Subtract(double n1, double n2)
{
return n1 - n2;
}
}

The code above is quite straightforward. It only performs some simple arithmetic operations, but, as you can see, these operations are not influenced by any locale. The operation’s output will always be the same, whether the host’s locale is English or French.

Globalization Patterns in .NET (WCF (WS-I18N implementation))

Post a Comment