Click here to Skip to main content
15,908,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I've been doing a lot of surfing but couldn't find this out.

I want to connect to a WCF service but I have it's machine name (eg "DESK2"), rather than a DNS name.

C#
Uri uri = new Uri("http://localhost:8000/ServiceModelSamples/CalcService/CalculatorService");
			EndpointAddress adrs = new EndpointAddress(uri);
			CalculatorClient client = new CalculatorClient("WSHttpBinding_ICalculator", adrs);


Any ideas?

Many thanks
Ronny
Posted

Hi ronzu,
you can try it
I hope it's working fine.

IPAddress myIP = IPAddress.Parse(Request.UserHostName);
IPHostEntry GetIPHost = Dns.GetHostEntry(Request.UserHostName);
Response.Write(GetIPHost.HostName);
 
Share this answer
 
Thanks bojjaiah... but it didn't seem to work.

IPAddress.Parse from the documentation only accepts:
A string that contains an IP address in dotted-quad notation for IPv4 and in colon-hexadecimal notation for IPv6.

In any case it came up with FormatException when I just gave it a machine name ("DESK2").

I got the solution on another site.

The URI string does accept a machine name:

Uri uri = new Uri("http://DESK2:8000/ServiceModelSamples/CalcService/CalculatorService");

Sometimes the simplest thing actually works!

Cheers
Ronny
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900