I have to consume a web service in a secure server, in https, with certificate and login.
So i make a Service reference in VS2008.
static void Main(string[] args)
{
Console.WriteLine("Value of code TR3A ?\n");
String codeTR = Console.ReadLine();
string responseFromServer ="";
System.Net.ServicePointManager.CertificatePolicy = new MyPolicy();
serviceTrains.TrainServiceClient myTrainService = new serviceTrains.TrainServiceClient();
responseFromServer = myTrainService.GetListTrainsAtGare(codeTR).ToString();
console.WriteLine(responseFromServer);
}
In my console app, I want to write the json wich I retrieve, but i have an error :
InvalidOperationException : The Address property on ChannelFactory.Endpoint was null. The ChannelFactory’s Endpoint must have a valid Address specified.
but if i go to https://blabla.com/TrainService.svc/GetListTrainsAtGare/COE it works …
another problem : i can’t make myTrainService.Credentials , why ??
The error is telling you that you don’t have an endpoint specified. Normally, the web service reference will store the endpoint where you got the wsdl from in the app.config but you might have generated the code a different way and there is no default provided.
In your code you could try the following if the service has the Url property.
It’s also a good idea to put the endpoint in the config and reference the entry through
System.Configuration.ConfigurationManagerTo address your second question, maybe more suited for another SO question:
You will have to provide more context about the connection type and security expected to get an accurate answer.