WCF Duplex with return values

205 views
Skip to first unread message

mr.tim.long

unread,
Oct 30, 2008, 6:37:11 AM10/30/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi,

This issue has been driving me a little crazy.

I've setup a wcf service with duplex communication and it works well
for one way functions. i.e. my contract looks a bit like this

[ServiceContract(SessionMode=SessionMode.Required,
CallbackContract=typeof(ILogMessaging)]
public interface IMyContract
{
[OperationContract(IsOneWay=true)]
void DoSomething();
}

The implementation of DoSomething() invokes the callback of
effectively sends back a log message to the client, and it all works
nicely, the message appears at the client.

The problem is when I want to put in a function that returns a value
and uses the callback. So, for example:

[OperationContract]
DateTime WhatIsTheTime();

with implementation:
DateTime WhatIsTheTime()
{
Callback.LogMessage("you asked for the time");
return DateTime.Now;
}

The client ends up timing out, and throws a timeoutexception. I've
read that because the service is single-threaded you get a deadlock
situation where client and server are both waiting for each other to
finish, so I guess this is what is causing the timeout. The solution
they say is to set the concurrency behaviour to Reentrant or Multiple.

But I don't understand this. I've set my callback function to
IsOneWay=True, and besides, when debugging I can see that execution
moves past the Callback statement. So I don't know what the client is
waiting for. I've tried changing the concurrency behaviour to
Reentrant or Multiple, but that didn't make any difference (was i
doing it wrong?)

Is there a way around this, or is it not possible to have this type of
behaviour? Am I trying to have my cake and eat it?

Thanks for your help,
Tim

mr.tim.long

unread,
Oct 30, 2008, 8:41:15 AM10/30/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Turns out the problem wasn't the duplex communication after all.
My callback was trying to write to the UI, but that thread was being
used call the server, so it was blocking there.

I solved the problem by decorating the callback class with
[CallbackBehaviour(UseSynchronizationContext=false)] and writing to
the UI differently.

Thanks anyway,
Tim

Glenn

unread,
Oct 30, 2008, 1:48:45 PM10/30/08
to DotNetDe...@googlegroups.com
Don't you hate it when that happens?!?!?!
 
Can you call your server in a background thread?  Then your callback can simply use delegates to update the UI.
 
...Glenn

Reply all
Reply to author
Forward
0 new messages