简要地,
Visual Studio 2012 RC Silverlight 5 应用程序使用通过共享便携式库使用 ChannelFactory 技术托管在ASP.net 4 应用程序中的Game WCF 4 服务。NET4/SL5包含带有异步 CTP的iGame接口
图:
ASP.NET <=类库 (Game) <=便携式库 (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