Click here to Skip to main content
15,877,857 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +

WCF Test Client is getting response as escape sequence Json Format in IOS and Android.


But It is showing error for below format


Showing below error

400 Bad Request Show explanation Loading time: 15
Request headers
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36
Origin: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo
Content-Type: application/json
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Response headers
Cache-Control: private
Content-Length: 1780
Content-Type: text/html
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Wed, 23 Apr 2014 04:09:47 GMT

my WCF Sample code

      [WebInvoke(UriTemplate = "UpdateTrackDetails",
          Method = "POST")]
      int UpdateTrackDetails(string trackdetails);

public int UpdateTrackDetails(string trackdetails)
           int result = 0;
           TrackDetails _BusTrack = JsonConvert.DeserializeObject<TrackDetails>(trackdetails);

           using (var context = new SchoolBusTrackEntities())
                   new BusTrackDetail

                       BusID = Convert.ToInt32(_BusTrack.BusID),
                       Latitude = _BusTrack.Latitude,
                       Longitude = _BusTrack.Longitude,
                       TrackTime =DateTime.Now,

result = context.SaveChanges();
           return result;


I am using here HttpClient. Issue I am mainly getting for WCF service consuming by IOS and Android applications.

My sample wcf test client

static async Task Post(string BusID, string Latitude, string Longitude, string TrackTime)
using (HttpClient client = new HttpClient())
client.BaseAddress = new Uri("");
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
BusTrack1 _Bus = new BusTrack1();
_Bus.BusID = BusID;
_Bus.Latitude = Latitude;
_Bus.Longitude = Longitude;
_Bus.TrackTime = TrackTime;
string data = JsonConvert.SerializeObject(_Bus);//{"busid:12"}
HttpResponseMessage response = client.PostAsJsonAsync("SchoolBusTrack.svc/UpdateTrackDetails", data).Result;
if (response.IsSuccessStatusCode)
var product = await response.Content.ReadAsAsync<string>();


Thanks in advance...

1 solution

Try setting the content type to "application/json" on your clients when sending.
Share this answer
Santhosh23 23-Apr-14 1:30am    
already is there
Mehdi Gholam 23-Apr-14 1:54am    
Your error says "text/html"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900