wcf callback timeout when sending more than one messages

I have a wcf callback programm and it can send a message to a client.

If i try to send a second message the whole programm freezes and i get a timeoutexception.

Here is the servercode:

 public void SendMessageToClient(string computerName, string message)
    {
        foreach (var session in connectedClients.Values)
        {
            if (session.ComputerName == computerName)
            {
                var asyncResult = session.Callback.BeginOnMessageReceived(message, new AsyncCallback(OnPushMessageComplete), session.Callback);
                if (asyncResult.CompletedSynchronously)
                    CompletePushMessage(asyncResult);
            }
        }
    }
   void OnPushMessageComplete(IAsyncResult asyncResult)
    {
        CompletePushMessage(asyncResult);            
    }

    void CompletePushMessage(IAsyncResult asyncResult)
    {
        var callbackChannel = (IServiceCallback)asyncResult.AsyncState;
        try
        {
            callbackChannel.EndOnMessageReceived(asyncResult);
        }
        catch { }
    }

And this is the Callbackinterface:

 [OperationContract(IsOneWay = true, AsyncPattern = true)]
    IAsyncResult BeginOnMessageReceived(string message, AsyncCallback acb, object state);
    void EndOnMessageReceived(IAsyncResult iar);

And this is the client code:

[CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant, UseSynchronizationContext = false)]
public class ServiceHandler : IServiceCallback
{
    public delegate void MessageReceivedHandler(string message);
    public event MessageReceivedHandler OnMessageReceivedEvent;

    public void OnMessageReceived(string message)
    {
        if (this.OnMessageReceivedEvent != null)
            this.OnMessageReceivedEvent(message);
    }
}    

void callback_OnMessageReceivedEvent(string message)
    {
       setlb_info(message)
    }
public void setlb_info(string wert)
    {
        if (this.lb_info.InvokeRequired)
        {
            setlb_infoCallback d = new setlb_infoCallback(setlb_info);
            this.Invoke(d, new object[] { wert });
        }
        else
        {
            this.lb_info.Text = wert;
        }

    }

And if i try this:

Service.CurrentInstance.SendMessageToClient(client_name, message);

the client will get the message but if i call the same method a second time i get the timeoutexception (which is set to 1 minute).

I'm using code from this project(german):

http://www.flexbit.at/blog/wcf-duplex-zwischen-windows-sevice-und-gui-frontend/

I hope someone can help me because i can't finish my work if this function won't work.

Best regards

EDIT: I forgot a code on the client side:

 var callback = new ServiceHandler();
                callback.OnMessageReceivedEvent += new ServiceHandler.MessageReceivedHandler(callback_OnMessageReceivedEvent);
                var callbackInstanceContext = new InstanceContext(callback);
                client = new ServiceClient(callbackInstanceContext);
                client.Subscribe(System.Environment.MachineName);    

Answers


Try change [CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant, UseSynchronizationContext = false)] to [CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]


Need Your Help

Handle tap event for ListBoxItem template from code in Windows phone

c# xaml listbox windows-phone listboxitem

I am using Panorama Control in Windows Phone. In Panorama control I am dynamically adding Panorama Items from code. In PanoramaItem I have setup ListBox. I am setting up ItemTemplate for ListBox from

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.