GeoLocation数据类型与odata服务及其.Net生成的客户端代理之间不兼容

时间:2013-06-17 17:45:48

标签: serialization xml-serialization odata datacontractserializer jaydata

我正在尝试使用JayStorm的odata兼容云数据库功能进行概念验证。到目前为止,它很好,但我有一个大问题,适合odata服务客户端代理序列化类别。

我的odata服务网址为:https://open.jaystack.net/c72e6c4b-27ba-49bb-9321-e167ed03d00b/6494690e-1d5f-418d-adca-0ac515b7b742/api/mydatabase/

我创建一个简单的.Net控制台应用程序并为此服务添加服务引用。一开始看起来都很好,但是GeoLocation的服务器端数据类型之间存在不兼容性(json有效负载是:{“type”:“Point”,“coordinates”:[ - 71.56236648559569,42.451074707889646],“crs”:{ “properties”:{“name”:“EPSG:4326”})和客户端类型添加引用向导选择。它们似乎是非常不同的数据类型,只是客户端选择查询或客户端插入/更新不起作用。例如,下面的代码在SaveChanges();

行上引发异常
System.Data.Services.Client.DataServiceRequestException was unhandled
  HResult=-2146233079
  Message=An error occurred while processing this request.
  Source=Microsoft.Data.Services.Client
  StackTrace:
       at System.Data.Services.Client.SaveResult.HandleResponse()
       at System.Data.Services.Client.BaseSaveResult.EndRequest()
       at System.Data.Services.Client.DataServiceContext.SaveChanges(SaveChangesOptions options)
       at System.Data.Services.Client.DataServiceContext.SaveChanges()
       at JumpSeatDataImporter.Program.Main(String[] args) in c:\Projects\JumpSeat\Dev\JumpSeatWeb\JumpSeatDataImporter\Program.cs:line 24
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.Data.Services.Client.DataServiceClientException
       HResult=-2146233079
       Message=Format Exception: Invalid 'Point' format!
    at Function.$data.GeographyBase.validateGeoJSON (/usr/lib/node_modules/jaydata/lib/TypeSystem/Types/Geography.js:75:29)
    at GeographyPoint.GeographyBase (/usr/lib/node_modules/jaydata/lib/TypeSystem/Types/Geography.js:6:25)
    at new GeographyPoint (/usr/lib/node_modules/jaydata/lib/TypeSystem/Types/Geography.js:94:29)
    at $data.oDataConverter.fromDb.$data.GeographyPoint (/usr/lib/node_modules/jaydata/lib/Types/StorageProviders/oData/oDataConverter.js:55:64)
    at Airport.$data.Entity.$data.Class.define.constructor (/usr/lib/node_modules/jaydata/lib/Types/Entity.js:189:41)
    at Airport.Entity (eval at <anonymous> (/usr/lib/node_modules/jaydata/lib/TypeSystem/TypeSystem.js:463:20))
    at new Airport (eval at <anonymous> (/usr/lib/node_modules/jaydata/lib/TypeSystem/TypeSystem.js:463:20))
    at EntitySetProcessor.$data.Class.define.invoke (/usr/lib/node_modules/jaydata/lib/JayService/OData/EntitySetProcessor.js:61:38)
    at JSObjectAdapter.$data.Class.define.processRequest (/usr/lib/node_modules/jaydata/lib/JayService/JSObjectAdapter.js:89:37)
    at JSObjectAdapter.$data.Class.define.handleRequest (/usr/lib/node_modules/jaydata/lib/JayService/JSObjectAdapter.js:165:26)
       StatusCode=500
       InnerException: 

以下是代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Spatial;
using System.Text;
using System.Threading.Tasks;

namespace AirportDataImporter
{
    class Program
    {
        static void Main(string[] args)
        {
            var db = new AirprotDB.mydatabaseService(new Uri("https://open.jaystack.net/c72e6c4b-27ba-49bb-9321-e167ed03d00b/6494690e-1d5f-418d-adca-0ac515b7b742/api/mydatabase/"));

            //{"Name":"sfd","Abbrev":"sd","GeoLocation":{"type":"Point","coordinates":[-71.56236648559569,42.451074707889646],"crs":{"properties":{"name":"EPSG:4326"},"type":"name"}}}

            var airport = new JumpSeatDB.Airport();
            airport.Abbrev = "Foo";
            airport.Name = "Bar";

            airport.GeoLocation = GeographyPoint.Create(51.87796, -176.64603);
            db.AddToAirport(airport);

            db.SaveChanges();

            //var foo = db.Airport.ToList();


        }
    }
}

如果让客户端代理使用一个拟合(自定义声明的?)类,这将允许我往返数据,包括GeoLocation属性,我该怎么办?没有这个,我无法将数据从sql server和文件上传/更新到JayStorm ......

您应该能够通过向控制台应用添加服务并运行上面提供的代码来完全模拟我的问题。不要担心搞乱数据。

由于

1 个答案:

答案 0 :(得分:0)

地理类型现在只通过JSON格式公开(这可能会在中期发生变化),.NET默认使用XML,这留下了三个选项:

  • 使用Data Services Client 5.5.0和Data Services Tools 5.3使您的.NET应用程序以JSON格式工作(这会生成一个新的代理,它接受上下文中的Format属性) - 我无法实现这一点在.NET中,但我希望你比我好:)。
  • 您使用HTML5页面或node.js导入带有JayData库的POI
  • 您将csv文件发布到JayStorm服务操作,该操作处理该文件。您使用HttpRequest
  • 发布到服务操作