简体   繁体   中英

Get address from service reference C#

I have a project that has a service reference to a web service. Is there a way from the codebehind to get the actual http address of the service reference?

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属性。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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