1

I'm using the LogReceiverService target that comes with NLog to log to a remote logging service. My NLog configuration looks like so:

<target name="loggingservice" type="LogReceiverService" endpointAddress="http://logger:56998/ILoggingService" useBinaryEncoding="False" includeEventProperties="True" />

This works fine. However, if I change the endpointAddress to HTTPS:

<target name="loggingservice" type="LogReceiverService" endpointAddress="https://logger:56998/ILoggingService" useBinaryEncoding="False" includeEventProperties="True" />

Then I get the following WCF exception:

[ArgumentException: The provided URI scheme 'https' is invalid; expected 'http'.
Parameter name: via]
   System.ServiceModel.Channels.HttpChannelFactory`1.ValidateCreateChannelParameters(EndpointAddress remoteAddress, Uri via) +17130141
   System.ServiceModel.Channels.HttpChannelFactory`1.OnCreateChannelCore(EndpointAddress remoteAddress, Uri via) +52
   System.ServiceModel.Channels.ChannelFactoryBase`1.InternalCreateChannel(EndpointAddress address, Uri via) +116
   System.ServiceModel.Channels.ServiceChannelFactoryOverRequest.CreateInnerChannelBinder(EndpointAddress to, Uri via) +29
   System.ServiceModel.Channels.ServiceChannelFactory.CreateServiceChannel(EndpointAddress address, Uri via) +32
   System.ServiceModel.Channels.ServiceChannelFactory.CreateChannel(Type channelType, EndpointAddress address, Uri via) +100
   System.ServiceModel.ChannelFactory`1.CreateChannel(EndpointAddress address, Uri via) +564
   System.ServiceModel.ClientBase`1.CreateChannel() +58
   System.ServiceModel.ClientBase`1.CreateChannelInternal() +48
   System.ServiceModel.ClientBase`1.get_Channel() +464
   NLog.LogReceiverService.WcfLogReceiverClient.NLog.LogReceiverService.ILogReceiverClient.BeginProcessLogMessages(NLogEvents events, AsyncCallback callback, Object asyncState) +21
   System.ServiceModel.ClientBase`1.InvokeAsync(BeginOperationDelegate beginOperationDelegate, Object[] inValues, EndOperationDelegate endOperationDelegate, SendOrPostCallback operationCompletedCallback, Object userState) +249

I can visit https://logger:56998 in the browser, and it loads just fine after a warning about an untrusted certificate.

I've tried a few of the suggested binding configurations in this post, but none of them make any difference. Plus, none of those answers really explain what's going on, just ideas on how to fix it.

Community
  • 1
  • 1
Mike Christensen
  • 88,082
  • 50
  • 208
  • 326

1 Answers1

2

Finally figured this out. Basically, I overrode CreateWcfLogReceiverClient in the LogReceiverWebServiceTarget with my custom version:

protected override WcfLogReceiverClient CreateWcfLogReceiverClient()
{
    EndpointAddress address = new EndpointAddress(EndpointAddress);
    HttpBindingBase binding = address.Uri.IsHttps() ? (HttpBindingBase)new BasicHttpsBinding() : new BasicHttpBinding();

    return new WcfLogReceiverClient(binding, address);
}

It's also possible this could be done by providing an EndpointConfigurationName, but I gave up after three hours trying to figure that out.

However, still no go. I would get no exceptions, but the message was not sent. I was able to track this down by enabling WCF tracing, which showed a problem with the SSL cert.

The URL loaded fine in Chrome, but in IE it would provide an invalid cert warning. It seems IE will let you continue, but WCF treats this as a failure. I finally tracked this down to the fact that the cert was keyed by my IPv4 address, and the host name resolves to an IPv6 address. I simply had to run:

netsh http add sslcert ipport=[MyIpv6Address]:91 certhash=<Cert Hash>

And then it loaded in IE, as well as running in WCF.

Mike Christensen
  • 88,082
  • 50
  • 208
  • 326