we're sending HTTP request to Bing maps with address details to get back the address map point. The response of the HTTP request is read as stream async, this stream is then deserialized to Bing response format. When I deserialize, I'm getting this error: System.Runtime.Serialization.SerializationException : Error while deserializing the object of type Previseo.Workflows.BingResponse. Unexpected character '<'.
Your help is so appreciated.
I've used Fiddler to see the response of bings which sends it back in the form of JSON:https://i.stack.imgur.com/LPIeW.png
JSON returned as text:
{"authenticationResultCode":"ValidCredentials","brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png","copyright":"Copyright © 2019 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.","resourceSets":[{"estimatedTotal":1,"resources":[{"__type":"Location:http:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1","bbox":[46.175388336181641,5.1528801918029785,46.231620788574219,5.28734016418457],"name":"01000, Ain, France","point":{"type":"Point","coordinates":[46.203506469726563,5.2217612266540527]},"address":{"adminDistrict":"Auvergne-Rhone-Alpes","adminDistrict2":"Ain","countryRegion":"France","formattedAddress":"01000, Ain, France","locality":"Bourg-en-Bresse","postalCode":"01000"},"confidence":"High","entityType":"Postcode1","geocodePoints":[{"type":"Point","coordinates":[46.203506469726563,5.2217612266540527],"calculationMethod":"Rooftop","usageTypes":["Display"]}],"matchCodes":["Good"]}]}],"statusCode":200,"statusDescription":"OK","traceId":"e1464a431e5e46b9854053ed8ae76ba8|DU00000D78|7.7.0.0|Ref A: 865592F3CBB74AD6ADA8A71D8344F297 Ref B: DB3EDGE0817 Ref C: 2019-08-07T07:56:20Z"}
private MapPoint GetAddressMapPoint(string address, string ville)
{
int idx;
string postal, city, url;
HttpClient client;
HttpResponseMessage apires;
DataContractJsonSerializer jsonSerializer;
BingResponse bingResp = null;
idx = ville.IndexOf(" ");
postal = ville.Substring(0, idx);
city = ville.Substring(idx + 1);
url = BING_MAPS_BASE_ADDRESS + $"REST/v1/Locations/FR/{postal}/{city}/{address.Trim()}?key={BingMapsKey}";
client = new HttpClient();
apires = client.GetAsync(url).Result;
jsonSerializer = new DataContractJsonSerializer(typeof(BingResponse));
Stream stream = apires.Content.ReadAsStreamAsync().Result;
bingResp = (BingResponse)jsonSerializer.ReadObject(stream); //here is where I'm getting the error 'Unexpected caracter '<'
if (bingResp.resourceSets.Count > 0)
{
if (bingResp.resourceSets[0].resources.Count > 0)
{
var point = bingResp.resourceSets[0].resources[0].point;
return point;
}
}
return null;
}
public class BingResponse
{
[DataMember]
public string authenticationResultCode { get; set; }
[DataMember]
public string brandLogoUri { get; set; }
[DataMember]
public string copyright { get; set; }
[DataMember]
public List<ResourceSet> resourceSets { get; set; }
[DataMember]
public int statusCode { get; set; }
[DataMember]
public string statusDescription { get; set; }
[DataMember]
public string traceId { get; set; }
}