locked
How to get cleint ip address in wcf rest service ( webinvoke) RRS feed

  • Question

  • Hi 

    i want to get client ipaddress using below sample.

    http://www.danrigsby.com/blog/index.php/2008/05/21/get-the-clients-address-in-wcf/

     i have operationcontract method as "webInvoke" , it is giving ipaddress of the wcf host but not the actual client ipaddress. 

    here is my service contract . Inside GetIBookResults() method i a mtrying to get client ip address. using (

    public IList<Employee> GetIBookResults(string EValues)
            {

    OperationContext context = OperationContext.Current;
                    MessageProperties messageProperties = context.IncomingMessageProperties;
                    RemoteEndpointMessageProperty endpointProperty =
                        messageProperties[RemoteEndpointMessageProperty.Name]
                        as RemoteEndpointMessageProperty;


                    string clientIpAddress = endpointProperty.Address;)

    .....................................

    }

    here is my service contract

                              

    [ServiceContract]


        public interface IIBookService
        {


            [OperationContract]
            [WebInvoke(Method = "GET",
                ResponseFormat = WebMessageFormat.Json,
                BodyStyle = WebMessageBodyStyle.Bare,
                UriTemplate = "employees/EValues={EValues}")]
            IList<Employee> GetIBookResults(string EValues);

    }

    Please help me on this.

    Thursday, March 8, 2012 9:00 PM