[英]Get IP in WCF RIA Services
Does anybody know how can I get IP address of client with RIA services. 有人知道如何获取带有RIA服务的客户端的IP地址。 In WCF we have
OperationContext
for that. 在WCF中,我们为此提供了
OperationContext
。 But it doesn't work with RIA services. 但是它不适用于RIA服务。
您可以立即使用HttpContext.Current和API ...
You can use an Invoke Operation
in your DomainService
to get the IP adress like this: 您可以在
DomainService
使用Invoke Operation
来获取IP地址,如下所示:
[Invoke]
public string GetIPAddress()
{
return HttpContext.Current.Request.UserHostName;
}
In the client you should write: 在客户端中,您应该写:
YourContext context = new YourContext();
InvokeOperation invokeOperation = context.GetIPAddress();
invokeOperation.Completed += (s, args) =>
{
if (invokeOperation.HasError)
{
MessageBox.Show("Error");
invokeOperation.MarkErrorAsHandled();
}
else
{
string ip = invokeOperation.Value.ToString();
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.