I have already spent two days trying to find a solution to my problem and no results, so I would appreciate any hints.
What I am trying to achieve:
Briefly, I have created and published a WCF service (RESTful web services) with one method GetUsers that should return something like this:
[{"Name":"John","Surname":"Dell","GroupName":"Operator"}, {"Name":"John1","Surname":"Hp","GroupName":"Operator"}, {"Name":"John2","Surname":"Apple","GroupName":"Operator"}]
Unfortunately, when I test this method in the browser (http://localhost:28099/TestAPI.svc/GetUsers?inputName=Company, I get the response which includes the escape backslash and the double quotes at the beginning and at the end of the result, like below:
"[{\"Name\":\"John\",\"Surname\":\"Dell\",\"GroupName\":\"Operator\"}, {\"Name\":\"John1\",\"Surname\":\"Hp\",\"GroupName\":\"Operator\"}, {\"Name\":\"John2\",\"Surname\":\"Apple\",\"GroupName\":\"Operator\"}]"
The application consuming this webservice is telling me that this is not a valid JSON format.
In my web service method, I am getting the initial data in XML format, passing it to a datatable object, and then trying to convert it to JSON using the JSON.NET.
Below is the source XML:
<Root>
<row Name ="John" Surname="Dell" GroupName="Operator"/>
<row Name ="John1" Surname="Hp" GroupName="Operator"/>
<row Name ="John1" Surname="Apple" GroupName="Operator"/>
</Root>
Below is a snippet from my WCF code:
[ServiceContract]
public interface IWebServiceTest
{
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
String GetUsers(string inputName);
}
public class TestWCF: IWebServiceTest
{
Public String GetUsers(string inputName)
{
...................
StringReader stringReader1 = new StringReader(responseXMLResult.ToString());
XmlReader reader = XmlReader.Create(stringReader1);
ds.ReadXml(reader);
string json = JsonConvert.SerializeObject(ds.Tables[0], Newtonsoft.Json.Formatting.None);
return json
}