Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 202
Metallicraft Avatar asked Feb 24 '12 15:02

Metallicraft


2 Answers

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();
}
like image 89
Darin Dimitrov Avatar answered Oct 21 '22 17:10

Darin Dimitrov


Yes, the generated proxy will have a Url property.

like image 27
Roy Dictus Avatar answered Oct 21 '22 16:10

Roy Dictus