Uzyskanie adresu IP klienta w WCF 3.0
Najwyraźniej można łatwo uzyskać adres IP klienta w WCF 3.5, ale nie w WCF 3.0. Ktoś wie jak?
80
3 answers
To nie pomaga w 3.0, ale widzę ludzi, którzy znajdują to pytanie i są sfrustrowani, ponieważ próbują uzyskać adres IP klienta w 3.5. Oto jakiś kod, który powinien działać:
using System.ServiceModel;
using System.ServiceModel.Channels;
OperationContext context = OperationContext.Current;
MessageProperties prop = context.IncomingMessageProperties;
RemoteEndpointMessageProperty endpoint =
prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
string ip = endpoint.Address;
150
Author: Paul Mrozowski,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-03-09 17:53:59
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-03-09 17:53:59
Okazuje się, że możesz, o ile (a) Twoja usługa jest hostowana w serwisie internetowym (oczywiście) i (B) włączysz tryb zgodności AspNetCompatibility, w następujący sposób:
<system.serviceModel>
<!-- this enables WCF services to access ASP.Net http context -->
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
...
</system.serviceModel>
A następnie można uzyskać adres IP przez:
HttpContext.Current.Request.UserHostAddress
35
Author: Gaz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-12-02 17:21:00
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-12-02 17:21:00
Możesz, jeśli celujesz w. NET 3.0 SP1.
OperationContext context = OperationContext.Current;
MessageProperties prop = context.IncomingMessageProperties;
RemoteEndpointMessageProperty endpoint = prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
string ip = endpoint.Address;
Napisy: http://blogs.msdn.com/phenning/archive/2007/08/08/remoteendpointmessageproperty-in-wcf-net-3-5.aspx
Odniesienie: http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.remoteendpointmessageproperty.aspx