Briefly,
Visual studio 2012 RC Silverlight 5 Application consumes Game WCF 4 Service hosted in ASP.net 4 Application with ChannelFactory technique via Shared Portable Library .NET4/SL5 contains the iGame interface with Async CTP
Graph :
ASP.NET <= Class Library ( Game ) <= Portable Library ( iGame ) => Silverlight
Portable Library
[ServiceContract]
public interface iGame
{
[OperationContract]
Task<bool> Request ( string Key );
}
Class Library
[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)
What's wrong ? O_o
On your client side, your iGame
proxy is synchronous, and you're using fake-asynchronous wrappers around it to pretend it's asynchronous.
You need an asynchronous proxy. You may be able to do this by having VS2012RC regenerate the proxy, or you may be able to use TaskWsdlImportExtension
. I'm not sure if either solution will work in a portable library just yet.