Make WCF services to help use the same namespace when called from WCF Clients

We have two services, that can be called independently, but also can be used together. They have some common types, and if they called together, default Visual Studio proxy generation will create the same types in different namespaces.
There are multiple articles, that recommend to use command line SvcUtil instead of Visual Studio IDE.
The article How to reuse types across service endpoints suggests on client side manually update Reference.svcmap to include multiple <MetadataSources> and NamespaceMappings
Alternatively svcutil does allow you to specify multiple endpoints at a single time and utilize /r(/reference)  and /n(/namespace) parameters
.Another commonly discussing solution is to  Share Types Between WCF Service and Client., but client not always has access to served data types.

If you are writing services and wish to simplify coding by your clients, consider to create additional “wrapper” service, that will include implementations of both interfaces, that are implemented by original services.
The approach is mentioned in  Generating Proxy class file for webservices with sharing TYPES and Meineck.Net: WCF: Hosting multiple WCF services as one single service.
Note that wrapper service will describe methods from both services, but the actual methods are trivial- just redirect to individual services implementation.

Some compatibility differences between versions of SQL Server

In our environment most of developers use SQL Server 2008,but in production we have SQL Server 2005, and some databases still have compatibility level 80(SQL server 2000)
It sometimes causes problems
E.g. the SQL wtitten on SQL Server 2008

INSERT INTO[dbo].[SiteIds]  ([SiteID], [SiteCode],[ParentID])

    VALUES  (11,’ChildOfXX’,(select [SiteID] from [SiteIds] where SiteCode=’XX’))

GO

on SQL Server 2005 caused
Msg 1046, Level 15, State 1, Line 5
Subqueries are not allowed in this context. Only scalar expressions are allowed.
Fortunately it’s easy to rewrite in SQL 2005 acceptable form
 

DECLARE @SiteId int

    set @siteID=(select [SiteID] from [SiteIds] where SiteCode=’XX’)

INSERT INTO[dbo].[SiteIds]  ([SiteID], [SiteCode],[ParentID])  VALUES  (11,’ChildOfXX’,@siteID)

Another statement that generated in SQL Server 2008 should be removed in SQL Server 2005
ALTER TABLE dbo.Event SET (LOCK_ESCALATION = TABLE)

Also we had a stored procedure, that worked in  compatibility level 80(SQL server 2000), but caused an error after changing to compatibility level 90

Msg 145, Level 15, State 1, Line 4
ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
The explanation of the error can be found in SELECT DISTINCT and ORDER BY post.  In my case DISTINCT was completely redundant and I’ve removed it without any side effects.

T-SQL function to Get Maximum of values from the same row

 

 Based on the ScottPletcher   solution from http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_24204894.html
–SELECT dbo.GetMax(23, 45, 64, 22, 18, 224, 74, 138, 1, 98, 11, 86, 198)
–Naturally adjust data type to match what you actually need for your specific values
I’ve created a set of functions (e.g. GetMaxOfDates3 , GetMaxOfDates13 )to find max of up to 13 Date values.
CREATE FUNCTION GetMaxOfDates13 (
@value01 DateTime = NULL,  
@value02 DateTime = NULL,
@value03 DateTime = NULL,
@value04 DateTime = NULL,
@value05 DateTime = NULL,
@value06 DateTime = NULL,
@value07 DateTime = NULL,
@value08 DateTime = NULL,
@value09 DateTime = NULL,
@value10 DateTime = NULL,
@value11 DateTime = NULL,
@value12 DateTime = NULL,
@value13 DateTime = NULL
)
RETURNS DateTime
AS
BEGIN
RETURN (
SELECT TOP 1 value
FROM (
SELECT @value01 AS value UNION ALL
SELECT @value02 UNION ALL
SELECT @value03 UNION ALL
SELECT @value04 UNION ALL
SELECT @value05 UNION ALL
SELECT @value06 UNION ALL
SELECT @value07 UNION ALL
SELECT @value08 UNION ALL
SELECT @value09 UNION ALL
SELECT @value10 UNION ALL
SELECT @value11 UNION ALL
SELECT @value12 UNION ALL
SELECT @value13
) AS [values]
ORDER BY value DESC    
)
END –FUNCTION
GO
CREATE FUNCTION GetMaxOfDates3 (
@value01 DateTime = NULL,  
@value02 DateTime = NULL,
@value03 DateTime = NULL
)
RETURNS DateTime
AS
BEGIN
RETURN dbo.GetMaxOfDates13(@value01,@value02,@value03,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)
END –FUNCTION

 I haven’t considered UNPIVOT solution at the time of writing these functions, but it probably will be better.

Other solutions can be found at http://stackoverflow.com/questions/71022/sql-max-of-multiple-columns

http://www.sqlrecipes.com/sql_questions_answers/find_minimum_maximum_value_across_several_columns-11/

http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/007764d0-4a2d-4227-a4db-21fce471fbb3/

Localization Approach for ASP.NET Web site

String Resources

For string resources we will use local/global resources connecting to DB using DbResourceProvider from  “Creating a Data Driven ASP.NET Localization Resource Provider and Editor”
http://www.west-wind.com/presentations/wwdbresourceprovider/

It also has  DbResourceControl,  that shows controls with Localizable attribute and connect them to editor.

From http://guysmithferrier.com/Downloads/Top10TipsI18NASPNET.pdf and
http://www.guysmithferrier.com/post/2009/05/Localizing-ASPNET-MVC.aspx
To convert your HTML controls to equivalent ASP.NET server side controls, look at the I18NRefactorings (an add-in for VS) in the download at http://www.dotneti18n.com/Downloads.aspx (folder VS2010/ASPNETSpecifics/I18NRefactorings/I18NRefactorings in the 2010 zip)that will help automate this process.

Javascript Files

For javascripts we should separate localizable and non-localizable functions ,e.g. MyScript.js and MyScript.L10n.js(L10n stands for localization)  and
use ResourceUICultures to specify languages supported, e.g.(from Around the World with ASP.NET ASP.NET AJAX documentation Applications http://msdn.microsoft.com/en-us/magazine/cc135974.aspx#S3)

<asp:ScriptManager ID=”ScriptManager1″ runat=”server”

EnableScriptLocalization=”true”>

 <Scripts>

   <asp:ScriptReference Path=”MyScript.L10n.js”     ResourceUICultures=”ru”/>

 </Scripts>

</asp:ScriptManager>

Consider to use CompositeScript as described in
http://bellouti.wordpress.com/2008/09/14/combining-javascript-files-with-ajax-toolkit-library/ and
http://www.asp.net/ajaxlibrary/Combining%20Client%20Scripts%20into%20a%20Composite%20Script.ashx

ASP.NET Control to extract Resource information as JSON http://www.codeproject.com/KB/custom-controls/ResourcesToJavaScript.aspx

ScriptManager links
http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.enablescriptlocalization.aspx
http://msdn.microsoft.com/en-us/library/system.web.ui.scriptreferencebase.resourceuicultures.aspx
Other related links
Check if a language file is loaded for jQuery Globalization plugin

CSS Files
For CSS consider to use different themes for different cultures.
(examples not L10n specific
http://www.codeproject.com/KB/aspnet/dynamicThemes.aspx
Dynamically Applying Themes To Your ASP.Net Site With A Sitemap
ASP.NET Themes and Skins http://msdn.microsoft.com/en-us/library/ykzx33wh.aspx
http://www.codeproject.com/KB/aspnet/ThemesAndSkins.aspx

)
From http://stackoverflow.com/questions/3230576/load-different-css-for-site-localization
void Page_PreInit(object sender, EventArgs e)
{
   //If current context has no session then abort
   if (HttpContext.Current.Session == null)
       return;

   //Get current page context
   Page page = (Page)sender;

   switch (page.Culture) {
       case “en-US”:
           page.Theme = “en-USTheme”;
           break;
       case “fr-FR”:
           page.Theme = “fr-FRTheme”;
           break;
       default:
           page.Theme = “DefaultTheme”;
           break;
   }
Additionally  FallBack implementation is required.

Alternative css -related solutions
http://stackoverflow.com/questions/1221441/localize-images-via-css has a few suggestions, not something too attractive.
CSS Loader from resource http://forums.asp.net/t/1346799.aspx/1?CSS+with+localization not attractive for me- prefer to maintain css in file system

Concerns about themes from  http://forums.asp.net/t/1176552.aspx/1

I have abandoned the concept of Themes, at least the ASP.NET way. There are several reasons for that:

  1. One cannot control the CSS files used on a page through Theming. All CSS files in a Theme gets applied, even if you plan to use just one for a page.
  2. One cannot localize a Theme, one need to create a copy of the default and apply the changes to it, creating a theme that is culture specific.

 

The solution I opted for is to create my own Styles folder in which different ‘Themes’ are place in their respective subfolders. I can now control the CSS & apply text-direction when neccessary.

 

Localized Files

http://stackoverflow.com/questions/1982686/asp-net-localized-files
string cultureSpecificFileName = String.Format(“TOS_{0}.pdf”, CultureInfo.CurrentCulture.Name)
In the example given, the file would have to be named TOS_en-US.pdf. It you want to use the 2-letter ISO culture names, use CurrentCulture.TwoLetterISOLanguageName and then the file name would be TOS_en.pdf.
http://forums.asp.net/t/1039924.aspx/1?Themes+and+images+localization
You can create page specific resource files or global resource file and localize imageurl there.
For example, in Default.en-GB.aspx (in App_LocalResources): Image1.ImageUrl = “xxx”, while add meta:resourceKey=”Image1″ in .aspx to the Image to localize~
Or make a MyGlobal.en-GB.resx (in App_GlobalResources), Image1Url = “xxx”, and then add ImageUrl=”<%$ Resources:MyGlobal, Image1Url %>” to the Image to localize.

From http://www.globalme.net/web-localization/aspnet-localization
If possible, try avoiding images and graphics with embedded text. Using background images and retrieving the text from a resource file will make the localization effort much easier. If that is not possible, point the source of the image to the resx file which will let you easily change it depending on the language. This applies to other external assets such as pdf and doc files as well.

Tools for adding Localization to an ASP.NET project

Resharper for localization -http://www.jetbrains.com/resharper/webhelp/Resources__Index.html
If don’t have Resharper -try free Resource Refactoring Tool (http://resourcerefactoring.codeplex.com/)

Zeta Resource Editor http://zetaresourceeditor.codeplex.com/ also lists a few other tools.

Consider GetCultureFromUrl(Request.Url);
(from http://guysmithferrier.com/Downloads/Top10TipsI18NASPNET.pdf)

General Localization related links:

Localizing Resources for Component Libraries Overview

http://msdn.microsoft.com/en-us/library/bb398937.aspx#Localizing_Static_Script_Files_and_Their_Resources

http://www.beansoftware.com/ASP.NET-Tutorials/Globalisation-Multilingual-CultureInfo.aspx http://www.asp.net/general/videos/how-do-i-create-a-multi-lingual-site-with-localization

Generate a local resource file from an ASP.NET Web page

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/localization/default.aspx

http://asp-net-whidbey.blogspot.com/2006/03/aspnet-20-custom-resource-provider.html

Localize ASP.NET MVC 2 DataAnnotations validation messages with a custom resource provider

Why we have both CurrentCulture and CurrentUICulture

Extending the ASP.NET 2.0 Resource-Provider Model
BONUS CHAPTER 1.Resources and Localization
http://roundedcorners.wordpress.com/2010/04/10/resources-for-a-custom-resource-provider/