Fix for Error Accessing Remote Endpoint Address


The Windows networking team has released a fix for accessing the remote endpoint address of a socket that may affect WCF users. When an asynchronous call is made to a thread working with the socket, and the thread exits before the asynchronous call is processed, the wrong remote endpoint address might be returned.

WCF users could hit this bug causing the remote endpoint address for a TCP channel to not be available. A symptom that indicates you're having this particular problem is an occasional first chance exception where the top of the stack trace has these frames:

System.Net.IPEndPoint.Create(System.Net.SocketAddress)
System.Net.Sockets.Socket.get_RemoteEndPoint()
System.ServiceModel.Channels.SocketConnection.get_RemoteIPEndPoint()

The exception is often that the IPEndPoint has an invalid AddressFamily or another error that the constructed address is not valid.

You can get the fix from KB article 973155.

Comments (3)
  1. Steve Nutt says:

    This is a good fix. On a similar subject, I would like to have some way of detecting the MAC address or serial number of a remote endpoint. I can’t seem to do this at the moment.

  2. Israel Aece says:

    I have a service (HTTP) that is using UserNamePasswordValidator class to customize the user authentication. All works well, but I need to log IP Address of clients, independently if login successes or fail.

    So, to get IP Address from request, I’m using RemoteEndpointMessageProperty class to do this. I’m using it inside of UserNamePasswordValidator (Validate method) class, but the RemoteEndpointMessageProperty class depends of the OperationContext, that at this point, is always null.

    Exploring other sections, I was be able to create a Message Inspector (IDispatchMessageInspector), and in AfterReceiveRequest method, I can access username and IP Address from Message. But the problem here is that this code will run only if login is valid.

    Nick, is there other way to resolve my problem?

  3. Hi Israel,

    In an IIS hosted service you should be able to enable ASP.NET compatibility mode and retrieve the remote client endpoint yourself from the ASP.NET http application context.

Comments are closed.

Skip to main content