Get address from service reference C#
Asked Answered
E

2

8

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

Edana answered 24/2, 2012 at 15:7 Comment(0)
D
9

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();
}
Dhole answered 24/2, 2012 at 15:13 Comment(1)
Superb. Thanks for the example.Edana
H
1

Yes, the generated proxy will have a Url property.

Hutch answered 24/2, 2012 at 15:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.