Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve the client's machine name from within a WCF Operation Contract?

I'm currently looking at the OperationContect.Current properties. Is there a (nested) property the will always return the machine name of the client? I'm currently using net.tcp binding, but would like to support additional bindings in the future.

Using .NET 3.5 SP1

like image 300
chilltemp Avatar asked Feb 17 '11 21:02

chilltemp


People also ask

How will you specify a method available to access by client in WCF?

With the service running, right click the project that will contain the WCF client proxy and select Add > Service Reference. In the Add Service Reference Dialog, type in the URL to the service you want to call and click the Go button. The dialog will display a list of services available at the address you specify.

How to consume WCF service using wsdl in c#?

Sure - you can copy the path+filename for the WSDL and paste that into the "Add Service Reference" dialog box in Visual Studio (or just type int the full path + WSDL file name). Alternatively, you can use the svcutil.exe command line utility to convert the WSDL file to your client proxy class.


1 Answers

You can get the remote endpoint's IP address from the current OperationContext's IncomingMessageProperties, eg:

RemoteEndpointMessageProperty messageProperty = OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
Console.WriteLine("Remote address is: {0}", messageProperty.Address);
like image 125
Chris Wenham Avatar answered Nov 07 '22 12:11

Chris Wenham