0

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 ??

Craysis
  • 45
  • 7

1 Answers1

0

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.

myTrainService.Url = "https://blabla.com/TrainService.svc/GetListTrainsAtGare/COE";

It's also a good idea to put the endpoint in the config and reference the entry through System.Configuration.ConfigurationManager

To 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.

Gerard Sexton
  • 3,114
  • 27
  • 36
  • Thanks for all, but i don't understand, i see everywhere the `Url` property, but i can't make that ... have any idea why ? – Craysis Aug 09 '12 at 07:32
  • How did you make the C# code for the reference? What kind of service is it, Web Reference or Service Reference? – Gerard Sexton Aug 09 '12 at 08:14
  • it's a service reference, but now it's ok, i used simply a httpWebRequest, easier ;) Thx ! – Craysis Aug 09 '12 at 08:41
  • Glad you got it! I try to stay away for service references and use web references. If you are not using soap, then httpWebRequest is the way to go :) – Gerard Sexton Aug 09 '12 at 09:10