Search code examples
c#ip-addresscode-behindservice-reference

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


Solution

  • 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();
    }