0

EF4 と WCF で STE を実装すると、このエラーを受け取りました

「ID 'NorthwindModel.Customer' を持つ型のオブジェクト マッピングが見つかりませんでした。」

(単一のプロジェクトで)STEを使用していない場合、このコードは機能しています。

チュートリアル: 自己追跡エンティティをシリアル化する

これが私のコードです

WCF:

Public Class Service1
Implements IService1

  Public Function GetData(ByVal query As String) As List(Of DbDataRecord) Implements IService1.GetData
  Try
     Using ctx = New NorthwindEntities()
        Return New ObjectQuery(Of DbDataRecord)(query, ctx).ToList 'Here is the error.
     End Using
  Catch ex As Exception
     Dim theFault As New ServFault()
     theFault.Reason = ex.Message.ToString()
     Throw New FaultException(Of ServFault)(theFault, ex.Message.ToString)
  End Try
End Function

Public Function GetOrderByCustomer(customerId As String) As System.Collections.Generic.List(Of Entities.Order) Implements IService1.GetOrderByCustomer
  Try
     Using ctx = New NorthwindEntities()
        Return (From ord In ctx.Orders Where ord.CustomerID = customerId).ToList
     End Using
  Catch ex As Exception
     Dim theFault As New ServFault()
     theFault.Reason = ex.Message.ToString()
     Throw New FaultException(Of ServFault)(theFault, ex.Message.ToString)
  End Try

End Function
End Class

WCF 構成

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
   <connectionStrings>
      <add name="NorthwindEntities" connectionString="metadata=res://*/NWDModel.csdl|res://*/NWDModel.ssdl|res://*/NWDModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(local);initial catalog=Northwind;persist security info=True;user id=sa;password=145837;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
   </connectionStrings>
</configuration>

WCF クライアント:

Module Module1

   Sub Main()
      Dim srv As New Service1Client
      Dim query As String
      Dim lst As List(Of DbDataRecord)

      Console.WriteLine("Start...")

      Dim orders As List(Of Entities.Order)
      orders = srv.GetOrderByCustomer("ALFKI") 'This code is working
      Console.WriteLine("Success!!! Order Count: {0}", orders.Count)

      query = "SELECT p FROM Customers AS p"
      lst = srv.GetData(query)

      Console.WriteLine("Total Customer: {0}", lst.Count)

      srv.Close()
      Console.ReadLine()
   End Sub

End Module

誰かが私を案内してくれることを願っています。必要に応じて、上記のサンプルの完全なソースも利用できます

4

1 に答える 1

0

これはWCFでは機能しません。DbDataRecord抽象クラスではなく、常に実エンティティタイプを返送する必要があります。WCFは、使用される実際のタイプを認識している必要があります。EFの実際のタイプは、おそらくMaterializedDbRecord内部でシリアル化できないものです。

WCFを介してメソッドを公開する場合は、パラメーターと結果として単純型またはデータコントラクト/シリアル化型を使用する必要があります。STEはデータコントラクトであるため、直接使用します。これにより、クライアントから型指定されていないクエリを送信するという要件が明らかに破られますが、WCFのシナリオではありません。

クライアントでクエリを作成できるテクノロジを探している場合は、WCF Data Servicesを確認してください(ただし、STEはサポートされていません)。

于 2011-11-29T09:16:22.040 に答える