When trying to host my WCF service using Net Tcp channel through Windows Console, I have to comment the 4 lines of code everytime I want to make my service discoverable.
class Program
{
static void Main(string[] args)
{
using (ServiceHost host = new ServiceHost(typeof(MyLibrary.MyService)))
{
// The following four lines of code currently break the ability to update or recreate a reference to this service
// Configure the custom authorization policy which will invoke the custom role-permission model
**//List<IAuthorizationPolicy> policies = new List<IAuthorizationPolicy>();
//policies.Add(new CustomAuthorizationPolicy());
//host.Authorization.ExternalAuthorizationPolicies = policies.AsReadOnly();
//host.Authorization.PrincipalPermissionMode = PrincipalPermissionMode.Custom;**
// Instantiate the service listener
host.Open();
Console.WriteLine("The service is running and is listening on:" + Environment.NewLine);
// Iterate through all the configured service end points
foreach (ServiceEndpoint endPoint in host.Description.Endpoints)
{ // Do My Work
}
Console.WriteLine(Environment.NewLine + "Press any key to stop the service");
Console.ReadKey();
host.Close();
}
}
}
I can comment those 4 lines of code and make the service discoverable, add and update service references, etc. and then revert the code when I am done.
In Production, I am hosting the service through Windows Service so practically there is no show stopper.
I am trying to find out why would I have to comment those 4 lines of code everytime and is there a way to resolve this issue, though I have a way of bypassing this issue. Any hints would be a great help and appreciated.
Without knowing specifically what goes into the CustomAuthorizationPolicy it will be hard to say exactly, but my best guess would be that your policy is rejecting calls to the MEX endpoint because they do not meet your authorization requirements. If as you’re saying you are checking roles, this is likely because the MEX endpoint is not setup by default to support Windows authentication, so you would be getting an anonymous call and your eventual IsInRole check will fail because of that.