I am using VS2008 and I am trying to complete a tutorial found at http://community.opennetcf.com/blogs/cf/200711/WCF/An%20Introduction%20to%20WCF%20for%20Device%20Developers.pdf. I am however stuck halfway as I get a debug error :-
UriException is Unhandled Invalid URI: A port was expected because of there is a colon (':') present but the port could not be parsed.
This occurs after the declaration of a formatted string to a URI. Below is the code that I am using. What should I do to get around this?
using System;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Net;
namespace OpenNETCF.WCF.Sample
{
class Server
{
static void Main(string[] args)
{
string hostIP = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0].ToString();
#if CLIENT_DISCOVERY_BUILD
Uri address = new Uri(string.Format("http://localhost:8000/calculator", hostIP));
#else
Uri address = new Uri(string.Format("http://{0}:8000/calculator", hostIP)); //THE EXCEPTION IS BEING THROWN HERE
#endif
ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), address);
try
{
// Add a service endpoint
serviceHost.AddServiceEndpoint(typeof(ICalculator),new BasicHttpBinding(),"Calculator");
#if CLIENT_DISCOVERY_BUILD
// Enable metadata exchange
// this is needed for NetCfSvcUtil to discover us
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
serviceHost.Description.Behaviors.Add(smb);
#endif
serviceHost.Open();
Console.WriteLine(
"CalculatorService is running at " + address.ToString());
Console.WriteLine("Press <ENTER> to terminate");
Console.ReadLine();
// Close the ServiceHostBase to shutdown the service.
serviceHost.Close();
}
catch (CommunicationException ce)
{
Console.WriteLine("An exception occured: {0}", ce.Message);
serviceHost.Abort();
}
}
}
}