Working c# Example

252 views
Skip to first unread message

Phillip Vessey

unread,
Aug 15, 2017, 3:32:24 AM8/15/17
to A gathering place for the Open Rail Data community
Hi

Does anyone have a working c# example of how to connect to OpenLDBWS? I'm doing something like the below:

            AccessToken token = new AccessToken();
            token.TokenValue = "MYTOKEN";

            LDBServiceSoapClient ldb = new LDBServiceSoapClient();
            GetDepartureBoardResponse services = await ldb.GetDepartureBoardAsync(20, "DON", "SHF", FilterType.from, 0, 120);

Where does the access token come into it? I have tried looking through the API using intellisense and cant see anywhere where I pass in the access token. Would appreciate any example of how to get the connection working. I have pulled in the WSDL as a connected service reference and I can access the API elements just fine but I cant pass the access token.

Thanks

Peter Hicks (Poggs)

unread,
Aug 15, 2017, 5:08:45 AM8/15/17
to Phillip Vessey, A gathering place for the Open Rail Data community
Hello

> On 15 Aug 2017, at 07:47, Phillip Vessey <phillip...@gmail.com> wrote:
>
> [snip]
> Where does the access token come into it? I have tried looking through the API using intellisense and cant see anywhere where I pass in the access token. Would appreciate any example of how to get the connection working. I have pulled in the WSDL as a connected service reference and I can access the API elements just fine but I cant pass the access token.

The access token is passed as a SOAP header - I don’t think there’s a way of saying “this header is mandatory” in WSDL, so you need to construct it manualy and pass it in with your request.

Unfortunately, I’m not familiar with C#, but there are a few people on this list who are familiar with it.


Peter


Phillip Vessey

unread,
Aug 15, 2017, 1:51:54 PM8/15/17
to A gathering place for the Open Rail Data community, phillip...@gmail.com
I could probably get the header built but I don't know which part of the API to pass it too.
Hopefully someone can point me in that direction.

Ian Price

unread,
Aug 16, 2017, 3:34:55 AM8/16/17
to A gathering place for the Open Rail Data community
Hi Philip,
The access token is normally passed to the OpenLDBWS methods as the first parameter. Here's an example I've used...

var board = await new LDBServiceSoapClient().GetArrivalDepartureBoardAsync(token, (ushort)rows, stationId, null, FilterType.to, 0, 0);

You'll probably find it useful to look at the Huxley project that James Singleton put together. He includes a link to some .NET code that uses OpenLDBWS on GitHub...

Best regards, Ian

Phillip Vessey

unread,
Aug 16, 2017, 4:51:36 AM8/16/17
to A gathering place for the Open Rail Data community
Hi Ian

Looking at the api in visual studio the first param to GetArrivalDepartureBoardAsync is no longer token, it goes straight to (ushort)rows.

Phil

Ian Price

unread,
Aug 16, 2017, 6:10:18 AM8/16/17
to A gathering place for the Open Rail Data community
Hi Phil,
I can't explain that. If you look at the LDBService in Visual Studio's object browser and select, say, the GetArrivalDepartureBoardRequest item, does it not show the access token as the first parameter of that method?

Regards, Ian

Phillip Vessey

unread,
Aug 16, 2017, 7:10:24 AM8/16/17
to A gathering place for the Open Rail Data community

No sadly it doesn't.

Ian Price

unread,
Aug 16, 2017, 7:59:08 AM8/16/17
to A gathering place for the Open Rail Data community
Hi Phil,
Out of interest, when you added the service reference for OpenLDBWS, did you use the URL below?

And did that automatically add the following lines near the end of your solution web.config file?
<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="LDBServiceSoap">
          <security mode="Transport" />
        </binding>
        <binding name="LDBServiceSoap1" />
      </basicHttpBinding>
      <customBinding>
        <binding name="LDBServiceSoap12">
          <textMessageEncoding messageVersion="Soap12" />
          <httpTransport />
        </binding>
      </customBinding>
    </bindings>
    <client>
        binding="basicHttpBinding" bindingConfiguration="LDBServiceSoap"
        contract="Darwin.LDBServiceSoap" name="LDBServiceSoap" />
    </client>
  </system.serviceModel>

Regards, Ian

Phillip Vessey

unread,
Aug 16, 2017, 8:26:55 AM8/16/17
to A gathering place for the Open Rail Data community
Yep, that's the URL I used. I don't think I have a web.config file as testing from a universal windows project.

Phillip Vessey

unread,
Aug 16, 2017, 8:32:01 AM8/16/17
to A gathering place for the Open Rail Data community
Just created a WebProject to test and yes that code gets added to web.config - still the same results from the API.

Ian Price

unread,
Aug 16, 2017, 9:10:54 AM8/16/17
to A gathering place for the Open Rail Data community
Hi Phil,
I can't understand what's going wrong for you. I just created a new MVC solution myself, added a reference to OpenLDBWS and added the following API controller method to call GetArrivalDepartureBoardAsync and you can hopefully see in the screenshot that Intellisense is showing the token as the first method parameter. Can you see anything that's different to your code?


Regards, Ian

Phillip Vessey

unread,
Aug 16, 2017, 9:52:42 AM8/16/17
to A gathering place for the Open Rail Data community
Hi Ian

Thanks for your efforts in looking at this.

If I create a WebApplication using MVC structure and use the code in a controller then it seems fine, it allows the passing of Token in GetArrivalDepartureBoardAsync()

Putting the code in anything other than a controller, such as when building a universal windows app it doesn't allow the passing of that parameter.

Its very strange.

Phil

Ian Price

unread,
Aug 16, 2017, 10:57:50 AM8/16/17
to A gathering place for the Open Rail Data community
Hi Phil,
I'm afraid I only develop MVC apps in .Net. Somebody else on the forum that's more conversant with other .Net environments can hopefully advise you on how to use the WSDL with a UWP app.
Good luck, Ian
Reply all
Reply to author
Forward
0 new messages