[英]Get address from service reference C#
I have a project that has a service reference to a web service. 我有一个项目,其中包含对Web服务的服务引用。 Is there a way from the codebehind to get the actual http address of the service reference?
有没有办法从代码隐藏中获取服务引用的实际http地址?
Thanks 谢谢
You could retrieve it from the client proxy that was generated for you: 您可以从为您生成的客户端代理中检索它:
using (var client = new ServiceReference1.MyServiceClient("*"))
{
string address = client.Endpoint.Address.Uri.ToString();
}
or if you are having multiple endpoints in your config file: 或者如果您的配置文件中有多个端点:
using (var client = new ServiceReference1.MyServiceClient("MyService"))
{
var address = client.Endpoint.Address.Uri.ToString();
}
是的,生成的代理将具有Url
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.