Hello, I've implemented IErrorHandler in a custom fault error handler on my WCF service and am trying to figure out how to capture the caller host name when credentials are not set properly. I can capture the host name correctly for other exception types when they pass through the ProvideFault method, but when you don't enter credentials correctly (e.g. misenter password) this method is not invoked and instead just HandleError is with an exception method of "The server has rejected the client credentials.".
OperationContext.Current is null. I also tried enabling asp.net compatibility mode but the HttpContext is also useless.
Does anyone know how to capture the caller host name in the HandleError method in this scenario where the ProvideFault method is bypassed?
Code in ProvideFault method which works correctly is the following. I can then access the key/value pairs off of the Data property of the exception in the HandleError method. Again problem though is the ProvideFault method is not invoked in my scenario as described above.
OperationContext context = OperationContext.Current;
string ipAddress = null;
if (context != null)
{
MessageProperties msgProps = context.IncomingMessageProperties;
if (msgProps.ContainsKey(RemoteEndpointMessageProperty.Name))
{
var endpointProp = msgProps[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
if (endpointProp != null)
{
ipAddress = endpointProp.Address;
error.Data.Add("IPAddress", ipAddress);
error.Data.Add("ClientHostName", Dns.GetHostEntry(ipAddress).HostName);
error.Data.Add("Port", endpointProp.Port);
}
}
}