none
obtain client address inside service

    Question

  • Hi

    I wish to get hold of the clients IP address, mac address and computer name within a service that is exposed using a net.tcp binding. Is this possible and, if so, how can it be obtained?

    Thanks in advance

    Ant

    Monday, April 10, 2006 4:14 PM

Answers

  • Sorry, I think I misread the question.  I thought you were looking for the server data. 

    You could put the data inside a custom soap header on the client for reading on the server.

    Thanks,

    Scott

    Monday, April 10, 2006 4:25 PM

All replies

  • Well I don't know about the ip and mac but you can get the machine name using System.Environment.MachineName.

    The other networking data is probably available through some other class, although I couldn't tell you what it is off the top of my head.

    Thanks,

    Scott

    Monday, April 10, 2006 4:20 PM
  • Actually there is an System.Net.IPAddress class.  Go ahead and see if that's what you're looking for.

    Thanks,

    Scott

    Monday, April 10, 2006 4:21 PM
  • Sorry, I think I misread the question.  I thought you were looking for the server data. 

    You could put the data inside a custom soap header on the client for reading on the server.

    Thanks,

    Scott

    Monday, April 10, 2006 4:25 PM
  • Thanks Scott, it is the clients data I'm after. I'm fairly new to Indigo and I've not done any manipulation at the SOAP level. Is this a reasonably straightforward thing to do?
    Monday, April 10, 2006 8:39 PM
  • Yes, it's pretty straightforward.

    You can create headers either by using a MessageContract.  (See this link for further details)

    http://windowssdk.msdn.microsoft.com/library/default.asp?url=/library/en-us/WCF_con/html/036fae20-7c55-4002-b71d-ac4466e167a3.asp

    or by getting the OperationContext and putting it in manually:

    Ie:

    ChannelFactory<IScott> CFScott = new ChannelFactory<IScott>(binding);

    IScott proxy = CFScott.CreateChannel(endptadr);

    MessageHeader<string> msgh= new MessageHeader<string> ( Environment.UserDomainName + "\\" + Environment.UserName,false,"urn:ScottsServer",true);

    msghun = msgh.GetUntypedHeader("Username", "urn:ScottsReallyCoolApp");

    OperationContextScope scope = new OperationContextScope((IContextChannel)proxy);

    OperationContext.Current.OutgoingMessageHeaders.Add(msghun);

    Server:

    string username = oc.IncomingMessageHeaders.GetHeader<string>("Username", "urn:ScottsReallyCoolApp","urn:ScottsServer");

    Thanks!

    Scott

    Monday, April 10, 2006 8:53 PM