简体   繁体   English

在WCF中获取调用者的主机名

[英]Getting caller's hostname in WCF

I'm replacing an existing web service with a WCF service and as the first step of migration I'm going to expose an endpoint with BasicHttpBinding until the client is upgraded later on in the year. 我正在用WCF服务替换现有的Web服务,作为迁移的第一步,我将使用BasicHttpBinding公开端点,直到客户端在今年晚些时候升级。

The plan is to host the new WCF service with a windows service (the service will only be called from within the intranet so there's no real need for HTTP), but exposing both Basic HTTP and Net.TCP endpoints so that the migration can happen in stages. 计划是使用Windows服务托管新的WCF服务(该服务只能在Intranet内调用,因此不需要HTTP),但是暴露基本HTTP和Net.TCP端点,以便迁移可以在阶段。

However, I'm having some trouble getting the caller's hostname in my WCF service, looking at the current web service code it's using Context.Request.UserHostName to get the hostname. 但是,我在WCF服务中获取调用者的主机名时遇到一些麻烦,查看当前使用Context.Request.UserHostName获取主机名的Web服务代码。 I've managed to get the caller's username and IP address but all the related permission/security services in the environment uses the hostname as opposed to IP, so is there any way for me to get the HostName inside my service? 我设法得到了呼叫者的用户名和IP地址,但环境中所有相关的权限/安全服务都使用主机名而不是IP,所以有什么方法可以让我在我的服务中获取HostName吗?

PS I've set the security mode to TransportCredentialOnly with clientCredientialType set to Windows PS我已将安全模式设置为TransportCredentialOnly,并将clientCredientialType设置为Windows

Since you are not hosting in IIS, you can't use ASP.NET compatibility mode to get access to the HttpContext which would normally be present in an ASP.NET process. 由于您不是在IIS中托管,因此无法使用ASP.NET兼容模式来访问通常存在于ASP.NET进程中的HttpContext

Instead, you can use the GetHostEntry method on the Dns class in the System.Net namespace to get the IPHostEntry instance which will contain the aliases (DNS names) for the IP addresses that you are obtaining. 相反,您可以在System.Net命名空间中Dns上使用GetHostEntry方法来获取IPHostEntry实例 ,该实例将包含您要获取的IP地址的别名(DNS名称)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM