之间的类型不匹配。那么现在我试图打通我的DataContext的任何数据,我得到这个异常:WCF DataService的(CTP2):有客户端和我使用WCF DataService的CTP2与实体框架4.1服务
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: There is a type mismatch between the client and the service. Type 'Crm.Objects.Segmentation' is not an entity type, but the type in the response payload represents an entity type. Please ensure that types defined on the client match the data model of the service, or update the service reference on the client. at System.Data.Services.Client.AtomMaterializer.MaterializeResolvedEntry(AtomEntry entry, Boolean includeLinks) at System.Data.Services.Client.AtomMaterializer.Materialize(AtomEntry entry, Type expectedEntryType, Boolean includeLinks) at System.Data.Services.Client.AtomMaterializer.DirectMaterializePlan(AtomMaterializer materializer, AtomEntry entry, Type expectedEntryType) at System.Data.Services.Client.AtomMaterializerInvoker.DirectMaterializePlan(Object materializer, Object entry, Type expectedEntryType) at System.Data.Services.Client.ProjectionPlan.Run(AtomMaterializer materializer, AtomEntry entry, Type expectedType) at System.Data.Services.Client.AtomMaterializer.Read() at System.Data.Services.Client.MaterializeAtom.MoveNextInternal() at System.Data.Services.Client.MaterializeAtom.MoveNext() at System.Linq.Enumerable.d_b1
1.MoveNext() at System.Collections.Generic.List
1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable
1 source) at MangoCrm.Modules.Replication.ReplicaBuilder.GetItems[T](IEnumerable`1 query) at MangoCrm.Modules.Replication.ReplicaBuilder.BeginReplication() at MangoCrm.Modules.Replication.ReplicationWindowControl.b_0() --- End of inner exception stack trace --- at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Delegate.DynamicInvokeImpl(Object[] args) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
这里是我的代码:
var uri = new Uri(webServiceUrl);
var service = new DataServiceContext(uri);
MessageBox.Show(service.CreateQuery<Segmentation>("DbSegmentations").ToList().Count.ToString());
任何帮助吗?
UPDATE 现在确定我发现我的WCF响应包含一个修改的实体对象。那就是:
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<entry xml:base="http://localhost:99/Services/CrmDataService.svc/"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns="http://www.w3.org/2005/Atom">
<id>http://localhost:99/Services/CrmDataService.svc/DbSegmentations(guid'e9854210-85d1-4822-ba70-7e1d3d29cf62')</id>
<title type="text"></title>
<updated>2011-06-16T15:07:48Z</updated>
<author>
<name />
</author>
<link rel="edit" title="Segmentation" href="DbSegmentations(guid'e9854210-85d1-4822-ba70-7e1d3d29cf62')" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Companies"
type="application/atom+xml;type=feed"
title="Companies"
href="DbSegmentations(guid'e9854210-85d1-4822-ba70-7e1d3d29cf62')/Companies" />
<category term="Crm.Data.Segmentation" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<content type="application/xml">
<m:properties>
<d:Id m:type="Edm.Guid">e9854210-85d1-4822-ba70-7e1d3d29cf62</d:Id>
<d:Name>Promoter</d:Name>
<d:Description m:null="true" />
<d:ReplicaInfo m:type="Crm.Data.ReplicaInfo">
<d:CreateDate m:type="Edm.DateTime">2011-06-09T20:35:22.29</d:CreateDate>
<d:ModifyDate m:type="Edm.DateTime">2011-06-09T20:35:22.29</d:ModifyDate>
<d:CreatedById m:type="Edm.Guid">00000000-0000-0000-0000-000000000000</d:CreatedById>
<d:ModifiedById m:type="Edm.Guid">00000000-0000-0000-0000-000000000000</d:ModifiedById>
<d:IsDeleted m:type="Edm.Boolean">false</d:IsDeleted>
</d:ReplicaInfo>
</m:properties>
</content>
</entry>
这里有一个问题
<category
term="Crm.Data.Segmentation"
scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"
/>
所以,问题是为什么我Crm.Objects.Segmentation成为Crm.Data.Segmentation?何改回来?
UPDATE2 我认为问题出在我的数据上下文中。数据上下文有一个名称空间Crm.Data。我的实体在Crm.Objects中。然后我使用4.0.0 WCF一切都很好,但然后我切换到CTP2我的实体获取Crm.Data命名空间,而不是一个正确的Crm.Objects
我有我的解决方案有3个项目:1.客户端应用程序2.实体对象项目3个网站与WCF服务项目。所以1和3对2个项目有相同的参考。我相信我在这两个项目中都使用了相同的参考。 – DolceVita 2011-06-16 13:18:13
我也开始更新WCF服务CTP2 – DolceVita 2011-06-16 13:22:35
上面的代码是从您的客户端应用程序后,出现此错误。它可能会将分段解析为Entity Objects项目中的一个,或者由WCF代理生成的一个。 – 2011-06-16 13:22:42