简而言之,
Visual Studio 2012 RC Silverlight 5应用程序消耗 ASP.net 4应用程序中托管的游戏 WCF 4服务使用ChannelFactory技术通过共享可移植库.NET4 / SL5 包含 iGame 界面与异步CTP
图表
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 );
}
}
Silverlight的
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 ) );
}
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
答案 0 :(得分:2)
在您的客户端,您的iGame
代理同步,并且您正在使用fake-asynchronous wrappers来假装它是异步的。< / p>
您需要一个异步代理。您可以通过让VS2012RC重新生成代理来执行此操作,或者您可以use TaskWsdlImportExtension
。我不确定这两种解决方案是否都可以在便携式库中运行。