Search code examples
c#wcf

How to specify a URL param API token, when using ClientBase?


I am trying to learn how to use WCF. I am writing a client library using System.ServiceModel.ClientBase<TChannel>. I am not sure if this is WCF or not, but it's what I found when searching the web for WCF client examples.

Anyway, I'm trying to write a client for an HTTP-based API that requires a URL param provided access token. I can't figure out how to provide this though.

Is there a way I can access the request headers directory, or maybe a more idiomatic way of doing this?


Solution

  • It is not the appropriate way to use WCF client for consuming HTTP-based APIs. WCF transport is a bit more complicated and has a different structure (it normally wraps everything is a message envelope, etc).

    If you really want to feel all the pain and to do it using WCF, then you will need to declare a .NET interface for your HTTP Api and all the message contracts.

    See the example here: http://tech.pro/tutorial/981/creating-a-rest-client-using-wcf

    But, again, I would advice against doing this in the real life :)