首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >WCF异步CTP银灯

WCF异步CTP银灯
EN

Stack Overflow用户
提问于 2012-08-05 17:50:06
回答 1查看 891关注 0票数 1

简而言之,

Visual 2012 RC Silverlight 5应用程序通过共享的便携库使用ChannelFactory技术使用ASP.net 4应用程序中托管的游戏WCF 4服务。E29 4/SL5包含异步CTP的iGame接口

图:

ASP.NET <=类库(游戏) <=便携式图书馆( iGame ) => Silverlight

便携式图书馆

代码语言:javascript
运行
复制
[ServiceContract]
public interface iGame
{
    [OperationContract]
    Task<bool> Request ( string Key );
}

类库

代码语言:javascript
运行
复制
[ServiceBehavior ( InstanceContextMode = InstanceContextMode . Single , ConcurrencyMode = ConcurrencyMode . Multiple , UseSynchronizationContext = true )]
public class Game : iGame
{
    public async Task<bool> Request ( string Key )
    {
        return await Task . Factory . StartNew ( ( ) => true );
    }
}

银灯

代码语言:javascript
运行
复制
    private async void myButton_Click ( object sender , RoutedEventArgs e )
    {
        if ( await Messenger . Instance . Client . Request ( XXX . Text ) ) // Exception
            NavigationService . Navigate ( new Uri ( "/Views/YYY.xaml" , UriKind . Relative ) );
    }
  • Messenger是一个单例类,通过ChannelFactory启动和存储我的客户端代理。
代码语言:javascript
运行
复制
System.InvalidOperationException: The contract 'iGame' contains synchronous operations, which are not supported in Silverlight. Split the operations into "Begin" and "End" parts and set the AsyncPattern property on the OperationContractAttribute to 'true'. Note that you do not have to make the same change on the server.
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__0(Object state)

怎么了? O_o

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-05 18:09:15

在客户端,您的iGame代理是同步的,您使用它周围的假异步包装器来假装它是异步的。

您需要一个异步代理。您可以通过让VS2012RC重新生成代理来做到这一点,或者您可以使用TaskWsdlImportExtension。我还不确定这两种解决方案是否能在便携式库中工作。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11818674

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档