1

When I raise an exception in my WCF service. The built in WebErrorHandler exception handler itself fails trying to access OperationContext.Current.IncomingMessageProperties as it seems to have been disposed. The consequence is that the real error is masked, and I always get an HTML error output.

Why would my IncomingMessageProperties be disposed? The service returns a stream - not sure if that is relevant.

4

2 回答 2

0

我发现了问题。我正在创建一个 WebFaultException。现在我创建一个普通的异常并使用 IErrorHandler 将其正确序列化到客户端。

于 2012-08-20T14:00:21.247 回答
0

当我尝试从另一个方法而不是 OperationContract 方法访问 OperationContext.Current.IncomingMessageProperties 时,这发生在我身上。

要访问 OperationContext.Current.IncomingMessageProperties,请为 OperationContext 创建一个扩展方法以访问该属性

像这样的东西:

public static string GetClientIP(this OperationContext context)
        {
            string ip = "";
            MessageProperties messageProperties = context.IncomingMessageProperties;
            RemoteEndpointMessageProperty endpointProperty =
              messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;

            if (endpointProperty != null)
            {
                 ip = endpointProperty.Address;
            }

            return ip;
        }
于 2014-06-24T21:57:03.963 回答