0

I created a Web API which accepts Json string and returns an XML. I am trying to test my web API using fiddler and unable to test it.

My get method in code:

[HttpGet]        
        public XmlDocument GetXML([FromBody]string JsonString)
        { 
            System.Xml.XmlDocument xmlDocument = Newtonsoft.Json.JsonConvert.DeserializeXmlNode(JsonString);

In fiddler :When I provide the content type as application json(below is screen shot). It throws a HTTP 500 error. "An error has occurred.No MediaTypeFormatter is available to read an object of type 'String' from content with media type 'application/json'."

But when I provide the content-Type :application/xml. It successfully makes a connection to the web api but the Input parameter "JsonString" is null. enter image description here

Community
  • 1
  • 1
DaD
  • 95
  • 11

1 Answers1

0

From your screenshot though it looks like you ARE in fact passing a string because it start with an equals and quotes like ="{ ... }". This looks like a JSONP body. JSON would look start with curl braces like { ... }

If you need to accept JSONP have a look at this answer: JSONP with ASP.NET Web API

Community
  • 1
  • 1
Oliver
  • 35,233
  • 12
  • 66
  • 78
  • Oliver, I am trying to send a Json String. The client application who will be using my API will be passing the Json data in a String. – DaD Aug 27 '15 at 20:43