We have a Windows Service that makes a WCF service call. Normally, it works fine. However, occasionally when we restart the Windows Service, a MessageSecurityException is thrown and everything goes to toss and it is thrown again repeatedly thereafter.
One solution we found is setting AllowedImpersonationLevel to “Impersonation”. However, we don’t use any impersonation. Also, it is a random issue and not always reproducible. Hence, this solution would be irrelevant.
Any light that someone can shed on this would be highly appreciated.
The stack trace of the error message:
2010-12-24 23:18:42,581 [3] ERROR
[DataSync] – An error occured during
Data Sync [(null)]
System.ServiceModel.Security.MessageSecurityException:
The HTTP request is unauthorized with
client authentication scheme
‘Negotiate’. The authentication header
received from the server was
‘Negotiate,NTLM’. ->
System.Net.WebException: The remote
server returned an error: (401)
Unauthorized. at
System.Net.HttpWebRequest.GetResponse()
at
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan
timeout) —End of inner exception stack
trace —Server stack trace: at
System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest
request, HttpWebResponse response,
WebException responseException,
HttpChannelFactory factory) at
System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest
request, HttpWebResponse response,
HttpChannelFactory factory,
WebException responseException,
ChannelBinding channelBinding) at
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan
timeout) at
System.ServiceModel.Channels.RequestChannel.Request(Message
message, TimeSpan timeout) at
System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message
message, TimeSpan timeout) at
System.ServiceModel.Channels.ServiceChannel.Call(String
action, Boolean oneway,
ProxyOperationRuntime operation,
Object[] ins, Object[] outs, TimeSpan
timeout) at
System.ServiceModel.Channels.ServiceChannel.Call(String
action, Boolean oneway,
ProxyOperationRuntime operation,
Object[] ins, Object[] outs) at
System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage
methodCall, ProxyOperationRuntime
operation) at
System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage
message)
This is an environment Issue. The machine couldn’t connect to Domain controller, and hence failed to perform authentication, which caused this intermittent issue.