Aller au contenu | Aller au menu | Aller à la recherche

Tag - Post English

Fil des billets - Fil des commentaires

dimanche 17 février 2019

WCF: Support of wildcard on IIS10 and more

IIS 10 brings support for wildcard domains. However WCF does not support it!
We had a WCF service hosted on IIS (in an Azure CloudService to be more specific) and this website had hostname like "lille.monsite.com ; paris.monsite.com ; lyon.monsite.com …".

Here is the original configuration (was working as expected)

Having a wildcard SSL certificate *.monsite.com, we adapted the configuration to allow the website to respond to *.monsite.com and removed old hostnames. Doing this, the WCF service fails with an HTTP 500 error !

To make it simple : our service cannot load anymore, more precisely it cannot load its' binding configuration.

After some research, we found that WCF does not support host header of wildcard type : https://blogs.msdn.microsoft.com/dsnotes/2017/07/07/wcf-support-for-wild-card-host-header-at-iis-10-and-above/

To fix the problem : we added a fake header "localhost" at top of the header list. The trick here is to allow the service to load using this localhost header. Still, it will nicely respond to queries like "mycity.monsite.com"! Warning, this “non wildcard header” has to be first in the list to make the WCF service to load properly!

Here is the configuration :
and the result :


mardi 3 décembre 2013

[Code Sample] Copy Folder with sub-folders and files


  Here is a small c# method that manage copy of folders. The code is documented enough so I won’t give more details Clignement d'œil do not hesitate to use comments if any questions/remarks!

/// <summary>
/// Copy full folder to another
/// </summary>
/// <param name="sourceFolder">Source of files/folders</param>
/// <param name="destinationFolder">Destination</param>
/// <param name="filter">Filtering to get files, default is *.*</param>
/// <param name="overwriteDestinationFolder">Allow to drop destination folder before copy, if true next parameter is useless. Default is true.</param>
/// <param name="overwriteDestinationFiles">Allow to overwrite files that already exists in destination folder. Default is true, used only if [overwriteDestinationFolder] is false.</param>
/// <remarks>If errors occurs during any step of copy (overwriting open files, deleting locked folders, access denied operations, ...) 
/// this method will just rethrow the exceptions.</remarks>
private void CopyFolder(string sourceFolder, string destinationFolder, string filter = "*.*", bool overwriteDestinationFolder = true, bool overwriteDestinationFiles = true)
  //HACK: System.IO.Path.Combine lead to strange results when folders starts and/or ends with '\'
  sourceFolder = sourceFolder.Trim('\\');
  destinationFolder = destinationFolder.Trim('\\');
  if (overwriteDestinationFolder && System.IO.Directory.Exists(destinationFolder))
      System.IO.Directory.Delete(destinationFolder, true);
      //The delete command will send the delete to the OS.
      //Recreating the directory can throw exception because it may not be already deleted!
      while (System.IO.Directory.Exists(destinationFolder))
      //unable to drop the folder, try deleting content
      System.IO.Directory.GetDirectories(destinationFolder).ToList().ForEach(t =>
        System.IO.Directory.Delete(t, true);
        while (System.IO.Directory.Exists(t)) System.Threading.Thread.Sleep(1);
      System.IO.Directory.GetFiles(destinationFolder).ToList().ForEach(t =>
  if (!System.IO.Directory.Exists(destinationFolder))
  foreach (var fld in System.IO.Directory.GetDirectories(sourceFolder))
    //HACK : the GetFileName returns the last part of the path from the latest '\'. This allows to get the last "folder" in the folder tree :)
    //this : System.IO.Path.Combine(destinationFolder, System.IO.Path.GetFileName(fld))
    //will gives the new destination folder for recursive call
    //NOTE : if overwrite of destination folder is true, it has already been cleaned so no needs to send this again for subfolders
    CopyFolder(fld, System.IO.Path.Combine(destinationFolder, System.IO.Path.GetFileName(fld)), filter, false, overwriteDestinationFiles);
  foreach (var file in System.IO.Directory.GetFiles(sourceFolder, filter))
    System.IO.File.Copy(file, System.IO.Path.Combine(destinationFolder, System.IO.Path.GetFileName(file)), overwriteDestinationFiles);


  Hope this could help!


Version Française : ici