本文介绍了移动线程:Silverlight 4服务参考不承认DataServiceProtocolVersion.V3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Zack Picki最初在预发布论坛上发布了这个问题,我们正在关闭这个论坛。我在这里重新发布,所以它会引起一些注意:

Zack Picki originally posted this question in the pre-release forums, which we're closing down. I'm re-posting it here so it'll catch some eyeballs:

"


我无法让Silverlight 4引用June CTP的正确程序集。

I can't get Silverlight 4 to reference the correct assembly for June CTP.


在Web项目中,我引用了:

In the web project I have references to:


C:\Program Files(x86)\ Microsoft Office Services 2011年6月CTP\bin\.NETFramework\Microsoft.Data.Services.dll

C:\Program Files (x86)\Microsoft Data Services June 2011 CTP\bin\.NETFramework\Microsoft.Data.Services.dll


C:\Program Files(x86)\ Microsoft Office Services 2011年6月CTP\bin\.NETFramework\Microsoft.Data.Services.Client.dll

C:\Program Files (x86)\Microsoft Data Services June 2011 CTP\bin\.NETFramework\Microsoft.Data.Services.Client.dll


 

 


WCF数据服务具有"config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;"设置正确。

The WCF Data Service has "config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;" set correctly.


标记可能是问题,因为它最初用V2创建:

The markup may be the problem since it initialiy created with V2:


Factory =" System.Data.Services.DataServiceHostFactory,System.Data.Services,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089"

Factory="System.Data.Services.DataServiceHostFactory, System.Data.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"


对6月CTP V3是否正确?

is that correct for the June CTP V3?


 

 


我发现需要将March CTP的标记更改为:

I found that the markup needed to be changed for the March CTP to:


Factory =" System.Data.Services.DataServiceHostFactory,Microsoft.Data.Services.Delta,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089"

Factory="System.Data.Services.DataServiceHostFactory, Microsoft.Data.Services.Delta, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"


但这不适用于June CTP。

but this does not work with the June CTP.


 

 


在SL4中,我引用了:

In SL4 I have reference to:


C:\Program Files(x86)\ Microsoft Office Services 2011年6月CTP\bin\Silverlight\Microsoft.Data.Services.Client.dll

C:\Program Files (x86)\Microsoft Data Services June 2011 CTP\bin\Silverlight\Microsoft.Data.Services.Client.dll


 

 


当我添加服务引用时,它会自动添加对以下内容的引用:

When I add the service reference, it automatically keeps adding a reference to:


C:\Program Files(x86)\ Mysoftoft SDKs\Silverlight \v4.0 \ Library \ Client \ System.Data.Services.Client.dll

C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Libraries\Client\System.Data.Services.Client.dll


然后在创建冲突时删除。

which I then remove as it creates conflicts.


 

 


我需要设置" _context.AddAndUpdateResponsePreference = DataServiceResponsePreference.IncludeContent;"仅在V3中可用。

I need to set "_context.AddAndUpdateResponsePreference = DataServiceResponsePreference.IncludeContent;" which is only available in V3.


初始化时检查_context会告诉我协议版本是V2

Checking the _context when it is initialized keeps telling me that the Protocol Version is V2


因此,当我尝试保存数据时,我收到一条消息:

thus when I try to save my data I get a message saying:


"请求要求使用协议版本3.0,但数据服务上下文的MaxProtocolVersion设置为V2。将MaxProtocolVersion设置为更高版本,然后重试操作。"

"The request requires that version 3.0 of the protocol be used, but the MaxProtocolVersion of the data service context is set to V2. Set the MaxProtocolVersion to the higher version, and then retry the operation."


 

 


有没有人有这方面的解决方案?

Does anyone have a solution for this?


 

 


Zack"

Zack"

推荐答案

您看到的异常是在客户端上抛出的。 "DataServiceContext"类有一个带V3的新构造函数,它接受MaxProtocolVersion。 默认情况下,此参数设置为V2。 为了修复错误,您需要
构建您的DataServiceContext,将V3传递给此构造函数:。

The exception you are seeing is being thrown on the client.  The "DataServiceContext" class has a new constructor with V3 that takes in a MaxProtocolVersion.  By default this parameter is set to V2.  In order to fix the error, you need to construct your DataServiceContext passing in V3 to this constructor: http://msdn.microsoft.com/en-us/library/hh541123(VS.103).aspx.

你可以这样做方法的数量,但可能最简单的方法是在DataServiceContext的部分类中添加一个静态工厂方法,该方法接收System.Uri:

You can do this in a number of ways, but probably the easiest way is to add a static factory method in your DataServiceContext's partial class that takes in the System.Uri:

partial class NorthwindEntities
{
    private NorthwindEntities(Uri serviceRoot, DataServiceProtocolVersion maxVersion) : base(serviceRoot, maxVersion)
    {
    }

    public static NorthwindEntities Create(Uri serviceRoot)
    {
        return new NorthwindEntities(serviceRoot, DataServiceProtocolVersion.V3);
    }
}




每当创建上下文类而不是V2 Add生成的公共构造函数时,请使用此工厂方法服务参考。


Use this factory method whenever you are creating your context class instead of the public constructor generated by the V2 Add Service Reference.


这篇关于移动线程:Silverlight 4服务参考不承认DataServiceProtocolVersion.V3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 02:46