c# - 无法使用 Excel Power Query : invalid metadata? 连接到 OData v4 服务

标签 c# asp.net-web-api odata powerquery

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

DataSource.Error: OData: The feed's metadata document appears to be invalid.

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

这是元数据文档:

<?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 的错误。

最佳答案

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

谢谢, 哈德尔

关于c# - 无法使用 Excel Power Query : invalid metadata? 连接到 OData v4 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30306465/

相关文章:

c# - 在字典中创建自定义键

c# - 使用 WPF 显示流式富文本

c# - ASP.NET Web API 中带有可选参数的属性路由

c# - 部署后 swagger-ui 返回 500

c# - ASP.NET WebAPI 2 OData Controller 中的自定义 GET 操作

C#如何获取正在设置的属性的名称

C# 将多个数组合并为一个数组

c# - 如何从Request对象中获取HttpContent?

c# - OData 路径模板不是有效的 OData 路径模板

.net - 在 web api 中使用 odata 函数 isof