0

I'm trying to validate that a request is either json or xml data for our api. I know I can do something along the lines of

if (!( request.ContentType.Equals("text/json", StringComparison.InvariantCultureIgnoreCase) || request.ContentType.Equals("text/xml", StringComparison.InvariantCultureIgnoreCase)))
    //throw error here

But, I'm wondering if there is a better way to do this. I read up about Content Management but everything I'm finding seems to be for web api.

To give you an example of why I don't like this approach, one of our clients passes in text/xml; charset=UTF-8 and another passes in text / xml I can build checks for all of those but I was wondering if .net had anything built out there for this. I don't want to have to be hard coding something new, every new a new scenario comes up.

Erik Philips
  • 48,663
  • 7
  • 112
  • 142
Michael Andrews
  • 184
  • 6
  • 16

1 Answers1

0

You have two options if you want to stick to one WCF implementation.

1- Define multiple endpoints for your WCF service. One for SOAP/XML and one for REST/JSON (recommended): REST / SOAP endpoints for a WCF service

2- Define one endpoint but explicitly handle different content types: WCF Service contract to be both XML and Json serialized

Community
  • 1
  • 1
Sal
  • 3,673
  • 4
  • 19
  • 40