views:

35

answers:

1

I have an asp.net MVC 2 site setup to provide an API json/xml responses

eg

[GET] /Product/10

Returns an xml response of a product

Additionally, I have a WCF SOAP service embedded into the site which returns the same methods (same contract) but via SOAP

eg

GetProduct(10)

Returns an xml soap product.

I chose this route because I like the pure MVC approach + routing engine. My client would like to secure each request by using a key based/token authentication system.

They simply want to include a key in each request...

My question is..what is the best (and most accessible approach) to this? I was thinking of using a custom HTTP header however ... would some clients may have issues setting this value? Is this easy to do with a Soap client generated from a WSDL?

I would rather not pollute my business objects with key properties.

A: 

The answer depends on what kind of clients you want to support. You have a lot of choices:

  • Use wsHttpBinding for modern clients which support WS-Security
  • Use basicHttpBinding for clients which do not - you can run this over SSL if you like, and can use your choice of HTTP authentication techniques
  • Use basicHttpBinding with your custom headers if you like. Be aware that some clients do not support headers, or have to go to extra effort in order to use them. I, personally, don't mind making such clients squirm, but you might.

No matter which you choose, WCF will allow you to implement them all at the same time. You can have a single service serve the same contract on multiple endpoints. For instance, you could keep basicHttpBinding on https://services.company.com/myservice/basic, and at the same time support WS-Security on http://services.company.com/myservice/secure.

John Saunders
I'd like to go with the 3rd option... this doesn't have to be the most secure service. Do you have any examples of basicHttpBinding with cusotm heders? I can't even figure out how to add them to a service client in .NET?
dmose
Do you have to wrap each call like so?http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/4f8ab001-dafa-4347-bc41-95255ecc9230
dmose
@dmose: if you define the headers in the WSDL, then when you use "Add Service Reference", they should be in the client for you. I believe that will force WCF to use message contracts, which can have headers and bodies.
John Saunders
@dmose: I don't have experience with wrapping the calls. That was news to me.
John Saunders