title: Exception "MessageProperties object has been disposed" when trying to get the client IP in WCF service
body: <p>I use this code for get client IP in WCF service:</p>
  
  <pre><code>    public string GetClientIP()
      {
          var context = OperationContext.Current;
          MessageProperties prop = context.IncomingMessageProperties;
          var endpoint = prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
          string ip = endpoint.Address;
          return ip;
      }
  </code></pre>
  
  <p>when you try to run - throw exception "The System.ServiceModel.Channels.MessageProperties object has been disposed".</p>
  
  <p>This code does not work in one WCF service. Its web.config:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;system.web&gt;
      &lt;customErrors mode="Off" /&gt;
      &lt;identity impersonate="false" /&gt;
    &lt;/system.web&gt;
    &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"&gt;
        &lt;add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /&gt;
      &lt;/modules&gt;
      &lt;directoryBrowse enabled="true" /&gt;
    &lt;/system.webServer&gt;
    &lt;system.serviceModel&gt;
      &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" /&gt;
      &lt;standardEndpoints&gt;
        &lt;webHttpEndpoint&gt;
          &lt;standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="false" defaultOutgoingResponseFormat="Json" /&gt;
        &lt;/webHttpEndpoint&gt;
      &lt;/standardEndpoints&gt;
    &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>It is rest WCF service. Caller service-method signature like this:</p>
  
  <pre><code>[WebInvoke(Method = "POST", UriTemplate = "{someParameter}/MyMethod")]
  public string MyMethod(string someParameter, Stream stream)
  {
      var ip = GetClientIP();
  }
  </code></pre>
  
  <p>Search in Google nothing. Got any ideas?</p>