views:

333

answers:

1

We are using a WCF service with a Callback contract. Communication is Asynchronous. The service contract is defined as:

[ServiceContract(Namespace = "Silverlight", CallbackContract = typeof(ISessionClient),SessionMode = SessionMode.Allowed)]  
public interface ISessionService

With a method:

[OperationContract(IsOneWay = true)]  
void Send(Message message);

The callback contract is defined as

[ServiceContract]  
public interface ISessionClient

With methods:

[OperationContract(IsOneWay = true, AsyncPattern = true)]  
IAsyncResult BeginSend(Message message, AsyncCallback callback, object state);  
void EndSend(IAsyncResult result);

The implementation of BeginSend and EndSend in the callback channel are as follows:

public void Send(ActionMessage actionMessage)
{
    Message message = Message.CreateMessage(_messageVersion,
        CommsSettings.SOAPActionReceive, actionMessage, _messageSerializer);

    lock (LO_backChannel)
    {
        try
        {
            _backChannel.BeginSend(message, OnSendComplete, null);
        }
        catch (Exception ex)
        {
             _hasFaulted = true;
        }
    }
}

private void OnSendComplete(IAsyncResult asyncResult)
{
    lock (LO_backChannel)
    {
        try
        {
            _backChannel.EndSend(asyncResult);
        }
        catch (Exception ex)
        {
            _hasFaulted = true;
        }
    }
}

We are getting an InvalidOperationException: "Collection has been modified" on _backChannel.EndSend(asyncResult) seemingly randomly, and we are really out of ideas about what is causing this. I understand what the exception means, and that concurrency issues are a common cause of such exceptions (hence the locks), but it really doesn't make any sense to me in this situation.

The clients of our service are Silverlight 3.0 clients using PollingDuplexHttpBinding which is the only binding available for Silverlight. We have been running fine for ages, but recently have been doing a lot of data binding, and this is when the issues started.

Any help with this is appreciated as I am personally stumped at this time.

A: 

Since the problem started with the data binding, I am guessing that it has something to do with that.

This is what I think is happening:

  • There is a call to the wcf service
  • The databinding updates the data
  • The async call comes back, tries to update data, and finds that it has been changed

Alternativily it could be the overway around, but I think that the above is the most probable.

Shiraz Bhaiji