无法使用 Excel Power Query 连接到 OData v4 服务:元数据无效?

Posted

技术标签:

【中文标题】无法使用 Excel Power Query 连接到 OData v4 服务:元数据无效?【英文标题】:Cannot connect to OData v4 service with Excel Power Query: invalid metadata? 【发布时间】:2015-05-18 14:53:55 【问题描述】:

2015 年 4 月版的 Excel Power Query 宣传 OData v4 兼容性。但是,当我尝试连接到使用 Web API(Microsoft.Data.OData.5.6.0Microsoft.AspNet.WebApi.OData.5.5.1Microsoft.OData.Core.6.10.0)编写的 OData v4 服务时,我得到了一个

DataSource.Error:OData:Feed 的元数据文档似乎无效。

只有我一个吗?有没有办法调试这个?

这是元数据文档:

<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
  <edmx:DataServices>
    <Schema Namespace="MyCompany.Api.OData" xmlns="http://docs.oasis-open.org/odata/ns/edm">
      <EntityType Name="Position" OpenType="true">
        <Key>
          <PropertyRef Name="Id" />
        </Key>
        <Property Name="Id" Type="Edm.Int32" Nullable="false" />
        <Property Name="PositionId" Type="Edm.String" />
        <Property Name="Description" Type="Edm.String" />
        <Property Name="StartDate" Type="Edm.Date" />
        <Property Name="Status" Type="MyCompany.Positions.ValidationStatus" Nullable="false" />
        <Property Name="InstrumentTypeId" Type="Edm.Guid" Nullable="false" />
      </EntityType>
      <EntityType Name="Feed">
        <Key>
          <PropertyRef Name="Name" />
        </Key>
        <Property Name="Name" Type="Edm.String" Nullable="false" />
        <NavigationProperty Name="Deliveries" Type="Collection(MyCompany.Api.OData.Delivery)" />
      </EntityType>
      <EntityType Name="Delivery">
        <Key>
          <PropertyRef Name="ReferenceDate" />
        </Key>
        <Property Name="ReferenceDate" Type="Edm.DateTimeOffset" Nullable="false" />
        <NavigationProperty Name="Positions" Type="Collection(MyCompany.Api.OData.Position)" />
      </EntityType>
    </Schema>
    <Schema Namespace="MyCompany.Positions" xmlns="http://docs.oasis-open.org/odata/ns/edm">
      <EnumType Name="ValidationStatus">
        <Member Name="Invalid" Value="0" />
        <Member Name="Valid" Value="1" />
        <Member Name="Expired" Value="2" />
      </EnumType>
    </Schema>
    <Schema Namespace="Default" xmlns="http://docs.oasis-open.org/odata/ns/edm">
      <EntityContainer Name="Container">
        <EntitySet Name="Positions" EntityType="MyCompany.Api.OData.Position" />
        <EntitySet Name="Feeds" EntityType="MyCompany.Api.OData.Feed">
          <NavigationPropertyBinding Path="Deliveries" Target="Deliveries" />
        </EntitySet>
        <EntitySet Name="Deliveries" EntityType="MyCompany.Api.OData.Delivery">
          <NavigationPropertyBinding Path="Positions" Target="Positions" />
        </EntitySet>
      </EntityContainer>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>

编辑

在选项下的 Power Query 功能区中启用诊断后,我看到以下警告:

DataMashup.Trace Warning: 24579 : "Start":"2015-05-26T18:26:53.5539195Z","Action":"Engine/IO/OData/Create","ServiceUri":"http://localhost:54026/.../odata/v4","RequestUrl":"http://localhost:54026/.../odata/v4","RequestHeaders":"null","Exception":"Exception:\r\nExceptionType: Microsoft.Mashup.Engine1.Runtime.ValueException, Microsoft.Mashup.Engine.1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\r\nMessage: [DataSource.Error] OData: The feed's metadata document appears to be invalid.\r\nStackTrace:\n   at Microsoft.Mashup.Engine1.Library.OData.EdmModelProcessorBase`1.Build()\r\n   at Microsoft.Mashup.Engine1.Library.OData.V4.ODataEnvironment.Create(ServiceDocumentWrapper serviceDoc, Uri metadataUri, Value headers, String resourceKind, ResourceCredentialCollection credentials, IEngineHost host, ODataSettings settings, ODataUserSettings userSettings, Boolean useCachedCredentials)\r\n   at Microsoft.Mashup.Engine1.Library.OData.V4.ODataResponse.Create(Uri requestUri, HttpResponseData responseData, String resourceKind, Value headers, ResourceCredentialCollection credentials, IEngineHost host, ODataSettings settings, ODataUserSettings userSettings)\r\n   at Microsoft.Mashup.Engine1.Library.OData.ODataModule.GetFeed(String resourceKind, TextValue serviceUriValue, TextValue uriValue, Value headers, IEngineHost host, ResourceCredentialCollection credentials, ODataSettingsBase settings, ODataUserSettings userSettings, Boolean useCachedCredentials)\r\n\r\nInnerException\r\nException:\r\nExceptionType: System.InvalidOperationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\r\nMessage: Operation is not valid due to the current state of the object.\r\nStackTrace:\n   at Microsoft.Mashup.Engine1.Library.OData.V4.ODataTypeServices.GetTypeValueFromEdm(EdmPrimitiveTypeKind typeKind)\r\n   at Microsoft.Mashup.Engine1.Library.OData.V4.EdmModelProcessor.GetTypeValue(IEdmType type)\r\n   at Microsoft.Mashup.Engine1.Library.OData.V4.EdmModelProcessor.GetOrCreateTypeValue(Stack`1 processingTypes, IEdmType type)\r\n   at Microsoft.Mashup.Engine1.Library.OData.V4.EdmModelProcessor.GetOrCreatePropertyTypeValue(Stack`1 processingTypes, IEdmProperty property)\r\n   at Microsoft.Mashup.Engine1.Library.OData.V4.EdmModelProcessor.CreateRecordTypeValue(Stack`1 processingTypes, IEdmStructuredType type)\r\n   at Microsoft.Mashup.Engine1.Library.OData.V4.EdmModelProcessor.GetOrCreateTypeValue(Stack`1 processingTypes, IEdmType type)\r\n   at Microsoft.Mashup.Engine1.Library.OData.V4.EdmModelProcessor.ProcessTypes()\r\n   at Microsoft.Mashup.Engine1.Library.OData.EdmModelProcessorBase`1.Build()\r\n\r\n\r\n\r\n\r\n","ProductVersion":"2.22.4007.242 (Release-V2-Public)","ActivityId":"22edde60-34b3-49eb-8dda-75507d00be29","Process":"Microsoft.Mashup.Container.NetFX40","Pid":6244,"Tid":1,"Duration":"00:00:00.2893059"
DataMashup.Trace Warning: 24579 : "Start":"2015-05-26T18:26:53.8596010Z","Action":"SimpleDocumentEvaluator/BeginGetResult<IPreviewValueSource>/callback","Exception":"Exception:\r\nExceptionType: Microsoft.Mashup.Engine1.Runtime.ValueException, Microsoft.Mashup.Engine.1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\r\nMessage: [DataSource.Error] OData: The feed's metadata document appears to be invalid.\r\nStackTrace:\n   at Microsoft.Mashup.Evaluator.Interface.EvaluationResult2`1.get_Result()\r\n   at Microsoft.Mashup.Evaluator.SimpleDocumentEvaluator.<>c__DisplayClass1.<BeginGetResult>b__0(EvaluationResult2`1 result)\r\n\r\nInnerException\r\nException:\r\nExceptionType: System.InvalidOperationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\r\nMessage: Operation is not valid due to the current state of the object.\r\nStackTrace:\n   at Microsoft.Mashup.Engine1.Library.OData.V4.ODataTypeServices.GetTypeValueFromEdm(EdmPrimitiveTypeKind typeKind)\r\n   at Microsoft.Mashup.Engine1.Library.OData.V4.EdmModelProcessor.GetTypeValue(IEdmType type)\r\n   at Microsoft.Mashup.Engine1.Library.OData.V4.EdmModelProcessor.GetOrCreateTypeValue(Stack`1 processingTypes, IEdmType type)\r\n   at Microsoft.Mashup.Engine1.Library.OData.V4.EdmModelProcessor.GetOrCreatePropertyTypeValue(Stack`1 processingTypes, IEdmProperty property)\r\n   at Microsoft.Mashup.Engine1.Library.OData.V4.EdmModelProcessor.CreateRecordTypeValue(Stack`1 processingTypes, IEdmStructuredType type)\r\n   at Microsoft.Mashup.Engine1.Library.OData.V4.EdmModelProcessor.GetOrCreateTypeValue(Stack`1 processingTypes, IEdmType type)\r\n   at Microsoft.Mashup.Engine1.Library.OData.V4.EdmModelProcessor.ProcessTypes()\r\n   at Microsoft.Mashup.Engine1.Library.OData.EdmModelProcessorBase`1.Build()\r\n\r\n\r\n\r\n\r\n","ProductVersion":"2.22.4007.242 (Release-V2-Public)","ActivityId":"22edde60-34b3-49eb-8dda-75507d00be29","Process":"Microsoft.Mashup.Container.NetFX40","Pid":6244,"Tid":1,"Duration":"00:00:00.0040547"
DataMashup.Trace Warning: 24579 : "Start":"2015-05-26T18:26:53.2420994Z","Action":"SimpleDocumentEvaluator/BeginGetResult<IValue>","Exception":"Exception:\r\nExceptionType: Microsoft.Mashup.Engine1.Runtime.ValueException, Microsoft.Mashup.Engine.1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\r\nMessage: [DataSource.Error] OData: The feed's metadata document appears to be invalid.\r\nStackTrace:\n   at Microsoft.Mashup.Engine1.Library.OData.EdmModelProcessorBase`1.Build()\r\n   at Microsoft.Mashup.Engine1.Library.OData.V4.ODataEnvironment.Create(ServiceDocumentWrapper serviceDoc, Uri metadataUri, Value headers, String resourceKind, ResourceCredentialCollection credentials, IEngineHost host, ODataSettings settings, ODataUserSettings userSettings, Boolean useCachedCredentials)\r\n   at Microsoft.Mashup.Engine1.Library.OData.V4.ODataResponse.Create(Uri requestUri, HttpResponseData responseData, String resourceKind, Value headers, ResourceCredentialCollection credentials, IEngineHost host, ODataSettings settings, ODataUserSettings userSettings)\r\n   at Microsoft.Mashup.Engine1.Library.OData.ODataModule.GetFeed(String resourceKind, TextValue serviceUriValue, TextValue uriValue, Value headers, IEngineHost host, ResourceCredentialCollection credentials, ODataSettingsBase settings, ODataUserSettings userSettings, Boolean useCachedCredentials)\r\n   at Microsoft.Mashup.Engine1.Library.OData.ODataModule.GetFeed(String resourceKind, TextValue serviceUri, Value headers, Value options, IEngineHost host, Boolean isPrivileged)\r\n   at Microsoft.Mashup.Engine1.Library.OData.ODataModule.FeedFunctionValue.TypedInvoke(TextValue serviceUri, Value headers, Value options)\r\n   at Microsoft.Mashup.Engine1.Runtime.NativeFunctionValue3`4.Invoke(Value arg0, Value arg1, Value arg2)\r\n   at Microsoft.Mashup.Engine1.Runtime.NativeFunctionValue3`4.Invoke(Value arg0)\r\n   at Microsoft.Mashup.Engine1.Runtime.FunctionValue.MetaTypeFunctionValue.Invoke(Value arg0)\r\n   at Microsoft.Mashup.Engine1.Runtime.SerializationApplyingModule.SerializableFunctionValue.Invoke(Value arg0)\r\n   at Microsoft.Mashup.Engine1.Language.FunctionInvocationExpression1.Execute(Value frame)\r\n   at Microsoft.Mashup.Engine1.Language.DebugExpression.Execute(Value frame)\r\n   at Microsoft.Mashup.Engine1.Language.FunctionInvocationExpression2.Execute(Value frame)\r\n   at Microsoft.Mashup.Engine1.Language.DebugExpression.Execute(Value frame)\r\n   at Microsoft.Mashup.Engine1.Language.RuntimeFunctionValue1.Invoke(Value arg0)\r\n   at Microsoft.Mashup.Engine1.Language.RecordExpression.RuntimeRecordValue.Force(Int32 index)\r\n   at Microsoft.Mashup.Engine1.Language.RecordExpression.RuntimeRecordValue.get_Item(Int32 index)\r\n   at Microsoft.Mashup.Engine1.Runtime.RecordValue.get_Item(String field)\r\n   at Microsoft.Mashup.Engine1.Language.FieldAccessExpression.Execute(Value frame)\r\n   at Microsoft.Mashup.Engine1.Language.RuntimeFunctionValue1.Invoke(Value arg0)\r\n   at Microsoft.Mashup.Engine1.Language.RecordExpression.RuntimeRecordValue.Force(Int32 index)\r\n   at Microsoft.Mashup.Engine1.Language.RecordExpression.RuntimeRecordValue.get_Item(Int32 index)\r\n   at Microsoft.Mashup.Engine1.Runtime.RecordValue.get_Item(Value key)\r\n   at Microsoft.Mashup.Engine1.Runtime.Library.Linker.BindFunctionValue.TypedInvoke(RecordValue environment, Value section, TextValue name)\r\n   at Microsoft.Mashup.Engine1.Runtime.NativeFunctionValue3`4.Invoke(Value arg0, Value arg1, Value arg2)\r\n   at Microsoft.Mashup.Engine1.Runtime.FunctionValue.Invoke(Value[] args)\r\n   at Microsoft.Mashup.Engine1.Language.ExpressionInvocationExpression.Execute(MembersFrame0& frame)\r\n   at Microsoft.Mashup.Engine1.Language.MembersFunctionValue0.Invoke()\r\n   at Microsoft.Mashup.Engine1.Language.ListExpression.RuntimeListValue.Force(Int32 index)\r\n   at Microsoft.Mashup.Engine1.Language.ListExpression.RuntimeListValue.get_Item(Int32 index)\r\n   at Microsoft.Mashup.Engine1.Runtime.ListValue.get_Item(Value key)\r\n   at Microsoft.Mashup.Engine1.Runtime.Library.List.ElementWithListCheckFunctionValue.Invoke(Value collection, Value key)\r\n   at Microsoft.Mashup.Engine1.Language.FunctionInvocationExpression2.Execute(MembersFrame1& frame)\r\n   at Microsoft.Mashup.Engine1.Language.MembersFunctionV","ProductVersion":"2.22.4007.242 (Release-V2-Public)","ActivityId":"22edde60-34b3-49eb-8dda-75507d00be29","Process":"Microsoft.Mashup.Container.NetFX40","Pid":6244,"Tid":1,"Duration":"00:00:00.6215902"

很遗憾,我没有看到任何特定于我们的 OData API 的错误。

【问题讨论】:

【参考方案1】:

您能与我们分享服务网址吗?如果它是公开的并且没有敏感数据:)。您是否也可以尝试在浏览器中加载元数据文档,它是否正确加载而没有错误? 如果它在浏览器中工作,那么我们将需要一个服务 url 来重现问题或提琴手跟踪。

谢谢, 哈迪尔

【讨论】:

不幸的是,它是非公开的,并且在一定程度上包含敏感数据。但它确实在浏览器中加载。我将更新我的问题以包含剥离的元数据 xml(我希望,我不会通过删除敏感部分来破坏任何东西...... :) 我无法仅从元数据中分辨出来,可能是在 OData 中解析它失败了。那么,如何打开跟踪,查看日志并告诉我是否在其中看到任何 OData 特定错误,或者私下与我共享日志? 启用跟踪:Power Query 功能区 -> 选项 -> 启用 Power Query 跟踪复选框 我打开了跟踪,我看到ValueExceptions 有两个不同的堆栈跟踪,一个在at Microsoft.Mashup.Engine1.Library.OData.V4.ODataTypeServices.GetTypeValueFromEdm(EdmPrimitiveTypeKind typeKind) 有一个内部InvalidOperationException。第二个没有内部异常,发生在Microsoft.Mashup.Engine1.Library.OData.EdmModelProcessorBase1.Build()`。所以基本上,我还是迷路了。如何私下与您共享日志?疯狂猜测:Power Query 是否支持枚举? 不不,这很好,我们现在已经深入了解了,您可以在此处复制跟踪中具有值异常的部分吗?【参考方案2】:

您可以尝试使用最近更新以支持 OData v4 的 OData Validator 服务:

http://services.odata.org/validation/#

事实上,它显示了您提供的元数据文档的一个错误,但这可能是也可能不是导致 PowerQuery 失败的问题。 今天我用我自己的 OData (v4) 服务测试了新的 PowerQuery 版本,它运行良好,但我直接使用 ODataLib / Microsoft.OData.Core 没有 Web API 集成。

【讨论】:

验证产生一个错误:结构化类型由零个或多个结构属性(表示为 edm:Property 元素)和导航属性(表示为 edm:NavigationProperty 元素)组成 .不知道这是指什么。

以上是关于无法使用 Excel Power Query 连接到 OData v4 服务:元数据无效?的主要内容,如果未能解决你的问题,请参考以下文章

在通过 Python 运行时维护 Excel 工作簿的 Power Query 连接

在 C# 中更改 Excel Power Query 连接字符串

Excel Power Query导入MySQL数据

Excel 表之间的组合的 Power Query 是啥?

Power Query Editor (Excel) - 错误处理 API 提要中的无数据

PowerBI 核心组件介绍(Power Query&Power Pivot & Power View& Power BI)