WCF 3.5 找到客户端用来访问服务的 url(服务器端) [英] WCF 3.5 find the url the client used to get to the service (server side)
问题描述
我试图找到客户端用来访问服务器的 url,(在服务器端).我尝试了以下方法:
I am trying to find the url the client used to get to the server, (on the server side). I have tried the following:
Uri url = OperationContext.Current.Channel.RemoteAddress.Uri;
Uri url = OperationContext.Current.Channel.Local.Uri;
Uri url = OperationContext.Current.EndpointDispatcher.EndpointAddress.Uri;
但这些似乎都不能正常工作.它们都返回服务器名称,(带有完全限定的域.例如 myserver.mydomain.local.即使我使用了 myserver/myservice.svc,它也会得到全名.
but none of these seemed to work correctly. They all return the server name, (with the fully qualifed domain. such as myserver.mydomain.local. Even if I used used myserver/myservice.svc it would get the full name.
此时我没有可用于测试的服务和域,请访问 mywebsite.com/myservice.svc 以查看它是否具有机器名称.
At this point I don't have a service and domain available to test going to mywebsite.com/myservice.svc to see if it has the machine name or not.
我想得到的结果(来自服务器):
The result I want to get (from the server would be):
http://mywebsite.com/myservice.svc
而不是
http://myserver.mydomain.local/myservice.svc
这似乎是目前正在发生的事情.
which is what seems to be happening at the moment.
推荐答案
OperationContext.Current.IncomingMessageHeaders.To
应该给出客户端用来连接到服务器的 Uri.
Should give the Uri that client used to connect to the server.
这篇关于WCF 3.5 找到客户端用来访问服务的 url(服务器端)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!