I am getting 400 bad request for WebMessageBodyStyle.Wrapped <b><u></u>Interface</b> public interface ITMCOtherService { /// <summary> /// Searching nearest post office and ATM machine loations /// </summary> /// <param name="SearchbyLatLonRequestData"></param> /// <returns>returns response nearest post office and ATM machine address</returns> [WebInvoke(Method ="POST", ResponseFormat=WebMessageFormat.Json, RequestFormat=WebMessageFormat.Json, BodyStyle=WebMessageBodyStyle.Wrapped, UriTemplate = "api/10/map/search/latlng/")] [OperationContract] string SearchbyLatLon(string SearchbyLatLonRequestData); <b><u></u>Serialization</b> public static string ConvertToJSON(this object obj) { JavaScriptSerializer serializer = new JavaScriptSerializer(); return serializer.Serialize(obj); } <b>Console App</b> public void BranchLocatorUsingLatLong() { SearchbylatlongRequest.RequestRootObject rootObj = new SearchbylatlongRequest.RequestRootObject(); var data = new SearchbylatlongRequest.Data { ApiKey = "0de82ab2-5741-433b-a48b-97302383c608", UDID = "45612312312312321", AppUserAgent = "AppuserAgent = Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5", AppVersion = 1.2, }; var Params = new SearchbylatlongRequest.Params { Lat = 51.439425, Long = 0.417455, FilterType = 3, }; rootObj.data = data; rootObj.Params = Params; string ServiceUrl = System.Configuration.ConfigurationManager.AppSettings["FRESOtherService"] + "/map/search/latlng/"; WebClient WC = new WebClient(); WC.Headers["Content-type"] = "application/json"; MemoryStream MS = new MemoryStream(); DataContractJsonSerializer JSrz = new DataContractJsonSerializer(typeof(string)); string json1 = Helper.ConvertToJSON(rootObj); JSrz.WriteObject(MS, json1); System.Text.UTF8Encoding en = new System.Text.UTF8Encoding(); byte[] res1 = WC.UploadData(ServiceUrl, "POST", MS.ToArray()); MS = new MemoryStream(res1); JSrz = new DataContractJsonSerializer(typeof(string)); string result = (string)JSrz.ReadObject(MS); Console.WriteLine(result); Console.ReadLine(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)