0

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)
4

1 に答える 1

1

これは、ここのバグ投稿に関連しているようです:問題 226: odata4j は WCF-$metadata を正しく認識しません

したがって、これを修正するには、現在の odata4j ソースに基づいて odata4j-0.8.0-SNAPSHOT-clientbundle.jar を作成するだけです。修正は 0.8.0-SNAPSHOT に既に含まれているため ( Issue 226 fix )

バグレポートを参照する前に、ここで質問して申し訳ありません。

于 2012-12-06T21:10:59.347 に答える