【发布时间】:2012-08-05 17:50:06
【问题描述】:
简单地说,
Visual Studio 2012 RC Silverlight 5 应用程序 使用 游戏 WCF 4 服务 托管在 ASP.net 4 应用程序通过共享 Portable Library .NET4/SL5 使用 ChannelFactory 技术包含带有 Async CTP
的 iGame 接口图表:
ASP.NET 类库(游戏) 可移植库(iGame)=> Silverlight
便携式图书馆
[ServiceContract]
public interface iGame
{
[OperationContract]
Task<bool> Request ( string Key );
}
类库
[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 );
}
}
银光
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 启动和存储我的客户端代理。
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
【问题讨论】:
-
是的,我的所有解决方案程序集都安装了异步 CTP,也没有内部异常:(
标签: c# wcf silverlight-5.0 async-ctp