【问题标题】:Android odata4j Consumer EntitySet not found未找到 Android odata4j Consumer EntitySet
【发布时间】:2012-12-03 19:53:35
【问题描述】:

我正在尝试将一些数据从 Android 放入 OData 服务器:

<edmx:Edmx Version="1.0">
  <edmx:DataServices m:DataServiceVersion="1.0" m:MaxDataServiceVersion="3.0">
    <Schema Namespace="DBModel">
      <EntityType Name="insertData">
        <Key>
          <PropertyRef Name="ID"/>
        </Key>
        <Property Name="ID" Type="Edm.Guid" Nullable="false"/>
        <Property Name="double_data" Type="Edm.Double"/>
      </EntityType>
    </Schema>
    <Schema Namespace="Data">
      <EntityContainer Name="DataEntities" m:IsDefaultEntityContainer="true" p6:LazyLoadingEnabled="true">
        <EntitySet Name="insertStuff" EntityType="DBModel.insertData"/>
      </EntityContainer>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>

我将数据发送到服务器的方法:

public class DataTransmitter {
  String serviceUrl = "http://url.tld/Data.svc";
  String entitySet = "insertStuff";

  ODataJerseyConsumer c = ODataJerseyConsumer.newBuilder(serviceUrl).build();

  void sendData(double data, UUID uuid) throws Exception {
    OEntity newLocation = c.createEntity(entitySet)
        .properties(OProperties.guid("ID", uuid.toString()))
        .properties(OProperties.double_("double_data", data))
        .execute();
}

每当我启动应用程序时,我都会在adb logcat 上收到以下错误:

org.odata4j.exceptions.NotFoundException: EdmEntitySet insertStuff is not found

我想我必须以某种方式包含命名空间DBModel。但我不知道怎么做,而且似乎在文档中找不到。

编辑:我添加了ODataConsumer.dump.all(true); 行,以查看客户端从服务器接收的内容。我可以在输出中看到如上所示的整个 $metadata

I/System.out( 2984): GET http://url.tld/Data.svc/$metadata
I/System.out( 2984): Accept: application/xml
I/System.out( 2984): User-Agent: odata4j.org
I/System.out( 2984): Status: 200
I/System.out( 2984): Cache-Control: no-cache
I/System.out( 2984): Content-Length: 1455
I/System.out( 2984): Content-Type: application/xml;charset=utf-8
I/System.out( 2984): DataServiceVersion: 1.0;
I/System.out( 2984): Date: Tue, 04 Dec 2012 17:39:34 GMT
I/System.out( 2984): Server: Microsoft-IIS/7.5
I/System.out( 2984): X-Android-Received-Millis: 1354642777769
I/System.out( 2984): X-Android-Sent-Millis: 1354642777536
I/System.out( 2984): X-AspNet-Version: 4.0.30319
I/System.out( 2984): X-Content-Type-Options: nosniff
I/System.out( 2984): X-Powered-By: ASP.NET
I/System.out( 2984): <edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
I/System.out( 2984):   <edmx:DataServices m:DataServiceVersion="1.0" m:MaxDataServiceVersion="3.0" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
I/System.out( 2984):     <Schema Namespace="DBModel" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
I/System.out( 2984):       <EntityType Name="insertData">
I/System.out( 2984):         <Key>
I/System.out( 2984):           <PropertyRef Name="ID" />
I/System.out( 2984):         </Key>
I/System.out( 2984):         <Property Name="ID" Type="Edm.Guid" Nullable="false" />
I/System.out( 2984):         <Property Name="double_data" Type="Edm.Double" />
I/System.out( 2984):       </EntityType>
I/System.out( 2984):     </Schema>
I/System.out( 2984):     <Schema Namespace="Data" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
I/System.out( 2984):       <EntityContainer Name="DataEntities" m:IsDefaultEntityContainer="true" p6:LazyLoadingEnabled="true" xmlns:p6="http://schemas.microsoft.com/ado/2009/02/edm/annotation">
I/System.out( 2984):         <EntitySet Name="insertStuff" EntityType="DBModel.insertData" />
I/System.out( 2984):       </EntityContainer>
I/System.out( 2984):     </Schema>
I/System.out( 2984):   </edmx:DataServices>
I/System.out( 2984): </edmx:Edmx>

因此客户端能够连接到服务器并且访问EntitySet insertStuff。但它仍然显示错误

E/MainActivity(  987): null
E/MainActivity(  987): org.odata4j.exceptions.NotFoundException: EdmEntitySet insertStuff is not found
E/MainActivity(  987):  at org.odata4j.edm.EdmDataServices.getEdmEntitySet(EdmDataServices.java:55)
E/MainActivity(  987):  at org.odata4j.internal.EdmDataServicesDecorator.getEdmEntitySet(EdmDataServicesDecorator.java:36)
E/MainActivity(  987):  at org.odata4j.consumer.ConsumerCreateEntityRequest.execute(ConsumerCreateEntityRequest.java:42)
.
.
.
E/MainActivity(  987):  at android.os.Handler.dispatchMessage(Handler.java:99)
E/MainActivity(  987):  at android.os.Looper.loop(Looper.java:137)
E/MainActivity(  987):  at android.app.ActivityThread.main(ActivityThread.java:4966)
E/MainActivity(  987):  at java.lang.reflect.Method.invokeNative(Native Method)
E/MainActivity(  987):  at java.lang.reflect.Method.invoke(Method.java:511)
E/MainActivity(  987):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
E/MainActivity(  987):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
E/MainActivity(  987):  at dalvik.system.NativeStart.main(Native Method)

【问题讨论】:

    标签: android odata edmx odata4j


    【解决方案1】:

    看来,这与此处的错误 postet 有关:Issue 226: odata4j doesn't recognize WCF-$metadata correctly

    所以要解决这个问题,我所要做的就是根据当前的 odata4j 源创建 odata4j-0.8.0-SNAPSHOT-clientbundle.jar。因为 0.8.0-SNAPSHOT (Issue 226 fix) 中已包含修复程序

    很抱歉在查阅错误报告之前在这里询问!

    【讨论】:

    • 太糟糕了,odata4j 已经被放弃了。我试图解决这个问题 4 小时。除了 odata4j 之外,还有更好的 WCF OData 客户端吗?
    猜你喜欢
    • 2013-01-22
    • 2022-01-12
    • 2020-10-25
    • 1970-01-01
    • 1970-01-01
    • 2016-01-04
    • 2020-11-27
    • 2017-01-06
    相关资源
    最近更新 更多