Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
36 lines (32 sloc) 1.09 KB
namespace azureatwork.Azure.NSB.Worker
{
using System;
using System.Diagnostics;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Web;
public static class RESTHost
{
public static WebServiceHost Host<TService, TContract>(string url)
{
try
{
Uri baseAddress = new Uri(url);
var serviceHost = new WebServiceHost(typeof(TService), baseAddress);
var binding = new WebHttpBinding
{
HostNameComparisonMode = HostNameComparisonMode.Exact // to work it Azure Worker Role
};
var endpoint = serviceHost.AddServiceEndpoint(typeof(TContract), binding, "rest");
endpoint.Behaviors.Add(new WebHttpBehavior { HelpEnabled = true });
serviceHost.Open();
return serviceHost;
}
catch (Exception exception)
{
Trace.TraceError(exception.Message);
}
return null;
}
}
}