c# - 如何从 WCF 操作契约(Contract)中检索客户端的机器名称?

标签 c# wcf operationcontext

我目前正在查看 OperationContect.Current 属性。是否有一个(嵌套的)属性将始终返回客户端的机器名称?我目前正在使用 net.tcp 绑定(bind),但希望将来支持其他绑定(bind)。

使用 .NET 3.5 SP1

最佳答案

您可以从当前 OperationContext 的 IncomingMessageProperties 中获取远程端点的 IP 地址,例如:

RemoteEndpointMessageProperty messageProperty = OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
Console.WriteLine("Remote address is: {0}", messageProperty.Address);

关于c# - 如何从 WCF 操作契约(Contract)中检索客户端的机器名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5034660/

相关文章:

c# - 查询不返回任何东西

c# - 我的 sql 数据库表中没有任何内容?

c# - 如何使用 Razor 从我的 View 中调用 Controller 操作?

c# - 将 OperationContext 传播到异步 WCF 调用中

c# - 当前 OperationContext 在 WCF Windows 服务中为 null

c# - 如何在 trustedinstaller 帐户下运行我的 "C#"应用程序?

c# - 如何在 ASP.Net MVC 应用程序中使用来自 WCF 身份验证服务的身份验证 cookie

wcf - 在控制台应用程序中托管 WCF 服务

.net - WCF 和 ASP.NET 与 https 的兼容模式

wcf - 使 WCF OperationContext 与 DI 和测试很好地配合使用