Asp.net web api Can';使用Web API 2在HttpPut上取消数据库地理位置搜索
我正在使用经度和纬度坐标创建一个特定点,并将其存储为Azure SQL中的DbGeography Location 如果我直接使用依赖项注入调用服务,那么具有DbGeography Location的类/实体就可以正常工作。我可以轻松地进行更新。当我在执行PUT之前使用Web服务SDK并对对象进行searialize时,调用HttpPut方法时会出现500错误。500错误来自API 如果dbgeography Location={SRID=4326;POINT(-94.7713931 33.8482415)},则失败。如果我将DbGeography设置为null,它就可以正常工作 我甚至在DbGeography位置字段上有一个Json转换器,它似乎在调试模式下作为一个步骤工作 现在,我将把Location设置为null,并在控制器中创建DbGeography点。有没有关于如何让它正常工作的想法 我认为Json.NET在=符号上有问题 这是我的转换器代码Asp.net web api Can';使用Web API 2在HttpPut上取消数据库地理位置搜索,asp.net-web-api,entity-framework-6,spatial,dbgeography,Asp.net Web Api,Entity Framework 6,Spatial,Dbgeography,我正在使用经度和纬度坐标创建一个特定点,并将其存储为Azure SQL中的DbGeography Location 如果我直接使用依赖项注入调用服务,那么具有DbGeography Location的类/实体就可以正常工作。我可以轻松地进行更新。当我在执行PUT之前使用Web服务SDK并对对象进行searialize时,调用HttpPut方法时会出现500错误。500错误来自API 如果dbgeography Location={SRID=4326;POINT(-94.7713931 33.84
public class DbGeographyConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return objectType.IsAssignableFrom(typeof(string));
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
//Handles issue with null DbGeography values
if (reader.TokenType == JsonToken.Null)
return default(DbGeography);
JObject location = JObject.Load(reader);
JToken token = location["Geography"]["WellKnownText"];
string value = token.ToString();
//If value is null lets return the default
if (value == null)
return default(DbGeography);
//If we get to here lets convert
var converted = DbGeography.FromText(value);
return converted;
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
// Base serialization is fine
serializer.Serialize(writer, value);
//Handle null values
//var dbGeography = value as DbGeography;
//serializer.Serialize(writer, dbGeography == null || dbGeography.IsEmpty ? null : value);
}
}
正如我所说,转换器似乎正在工作,但我得到一个未捕获的异常,它导致了500错误。这在评估模型状态之前发生
非常感谢您的帮助!提前谢谢