views:

78

answers:

2

Not sure if I'm doing something wrong ... but I'm trying to implement a WCF service that can be called from WCF. I implemented the async pattern on the client, and here's what the call looks like:

BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
EndpointAddress endpointAddress = new EndpointAddress(AccountServiceURL);
var personService = new ChannelFactory<IAccountService>(basicHttpBinding, endpointAddress).CreateChannel();

var result = personService.BeginRegister(username, password, email, null, null);
personService.EndRegister(result); // <-- failing here

It hangs on the "EndRegister" call ... it just sits there and does nothing. And firefox.exe becomes unresponsive. The server never seems to receive the call as I have a breakpoint on the method call. Perhaps someone can eyeball something I'm doing wrong?

The contract looks like this on the client:

[ServiceContract]
public interface IAccountService
{
    [OperationContract(AsyncPattern = true)]
    IAsyncResult BeginRegister(string username, string password, string email, AsyncCallback callback, Object state);

    void EndRegister(IAsyncResult result);
}

and like this on the server:

[ServiceContract]
public interface IAccountService
{
    [OperationContract]
    void Register(string username, string password, string email);
}
+1  A: 

If you are calling that on the UI thread (which you probably are) then its going to crash your Silverlight runtime. That last call...

personService.EndRegister(result);

...is going to block, and in my experience the Silverlight runtime really, really hates it when the UI thread gets blocked on an IO call like this. You should instead respond to an event or callback, and inside that event or callback handler then make the EndRegister call.

Jason Jackson
That was it! thanks Jason
Joel Martinez
A: 

As I can understand that's because of Silverlight's WCF infrastructure doesn't use ThreadPool at all. So, a call to BeginXXX isn't really async call...

I also stumbled at this very strange behavior:

var ar = svc.BeginXxx(null, null);
var response = svc.EndXxx(ar);

and our app handgs.

Shrike