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

时间:2015-05-18 14:53:55

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

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

2 个答案:

答案 0 :(得分:2)

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

谢谢, Hadeel

答案 1 :(得分:2)

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

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

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