Wierd exceptions when calling WCF more than once from a static class
-
I'm using Compact Framework 3.5 on a phone to contact a WCF-service, but I think my question is more related to this message board. When the code below is called a second time, from a class that is implemented as a singleton, it ends in som really unexpected errors. It works fine the first time it's run.
MaintenanceService svc = new MaintenanceService();
List<Assignment> assignments = svc.GetAssignments().ToList<Assignment>; // Fails hereThe second time, it randomly throws 2 different exceptions (only one each time): - Sometimes it's a TimeOutException (System.Net.HttpWebRequest... - in VS-generated code). - And Other times it's a ObjectDisposedException (system.threading.timer for the WCF-TimeOut - in VS-generated code). If I use the same code from a Button_Click in a Form, it works every time, so I know it's not the service that are causing the error. I really need som help on this one?
Michael9000 wrote:
from a class that is implemented as a singleton,
Is it your intent to reuse an existing client proxy? /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
Michael9000 wrote:
from a class that is implemented as a singleton,
Is it your intent to reuse an existing client proxy? /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
Not necessarily. I'm using a static Maintenance-class (where the previously posted code is called from a static method), because it has to make the same list of objects available throughout the entire app (Gui+Backend). Edit: svc.dispose don't make any difference after the code in opening-post. (Performance doesn't really matter - time does (my deadline is in approximately 48 hours).) Any ideas are welcome. I'm stuck (I'm probably thinking about this i a wrong way) ?
-
Not necessarily. I'm using a static Maintenance-class (where the previously posted code is called from a static method), because it has to make the same list of objects available throughout the entire app (Gui+Backend). Edit: svc.dispose don't make any difference after the code in opening-post. (Performance doesn't really matter - time does (my deadline is in approximately 48 hours).) Any ideas are welcome. I'm stuck (I'm probably thinking about this i a wrong way) ?
OK, I was just concerned you were reusing a cached client proxy. I tried the same thing a while ago (in the interests of not having to recreate the proxy) and ended up getting burned by (a) disposed objects and (b) the channel being in a faulted state if an uncaught exception occured on the server. Can you confirm that your static class is in fact using (or serving up) a new instance of the proxy every time it's used? /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
Not necessarily. I'm using a static Maintenance-class (where the previously posted code is called from a static method), because it has to make the same list of objects available throughout the entire app (Gui+Backend). Edit: svc.dispose don't make any difference after the code in opening-post. (Performance doesn't really matter - time does (my deadline is in approximately 48 hours).) Any ideas are welcome. I'm stuck (I'm probably thinking about this i a wrong way) ?
Some more thoughts:
- Have you tried setting the timeout of the client proxy (at run-time) to a comfortably high value?
- Is there an uncaught exception occuring on the service end?
- Is the returned list guaranteed to be not-
null
?
/ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
OK, I was just concerned you were reusing a cached client proxy. I tried the same thing a while ago (in the interests of not having to recreate the proxy) and ended up getting burned by (a) disposed objects and (b) the channel being in a faulted state if an uncaught exception occured on the server. Can you confirm that your static class is in fact using (or serving up) a new instance of the proxy every time it's used? /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
What you described is exactly whay I'm getting (a and b). Not entirely sure what you mean, but I create a new for each call
public static class
{
public static List<Assignment> Test()
{
MaintenanceService svc = new MaintenanceService();
List assignments = svc.GetAssignments().ToList;
svc.Dispose(); // <- this makes no difference
return assignments;
}
} -
What you described is exactly whay I'm getting (a and b). Not entirely sure what you mean, but I create a new for each call
public static class
{
public static List<Assignment> Test()
{
MaintenanceService svc = new MaintenanceService();
List assignments = svc.GetAssignments().ToList;
svc.Dispose(); // <- this makes no difference
return assignments;
}
}Does this help?
public static List Test()
{
// Create the proxy
MaintenanceService svc = new MaintenanceService();
svc.InnerChannel.OperationTimeout = new TimeSpan (1, 0, 0); // 1 hr timeout!// Get results List ret = svc.GetAssignments().ToList(); Debug.Assert (ret != null); // Return a separate list List assignments = new List(); foreach (Assignment a in ret) { assignments.Add (a); } return assignments;
}
/ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
Some more thoughts:
- Have you tried setting the timeout of the client proxy (at run-time) to a comfortably high value?
- Is there an uncaught exception occuring on the service end?
- Is the returned list guaranteed to be not-
null
?
/ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
You think like me :), that was som of the first things I tried - without success.
Ravi Bhavnani wrote:
Have you tried setting the timeout of the client proxy (at run-time) to a comfortably high value?
Yes, tried that as the first thing. Changed timeout to 180 seconds (server responds in less than 4 seconds).
Ravi Bhavnani wrote:
Is there an uncaught exception occuring on the service end?
Not likely. The server always responds with, at least, a empty List within 4 seconds. (same for another test-method that simply takes a string and returns the same string).
Ravi Bhavnani wrote:
Is the returned list guaranteed to be not-null?
Yes. (at minimum it's a empty List of objects).
modified on Monday, January 17, 2011 6:54 PM
-
Does this help?
public static List Test()
{
// Create the proxy
MaintenanceService svc = new MaintenanceService();
svc.InnerChannel.OperationTimeout = new TimeSpan (1, 0, 0); // 1 hr timeout!// Get results List ret = svc.GetAssignments().ToList(); Debug.Assert (ret != null); // Return a separate list List assignments = new List(); foreach (Assignment a in ret) { assignments.Add (a); } return assignments;
}
/ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
Did you just read my offline code or my mind!? That's 99,9% the original code except 'svc.innerC...' and my out-commented 'Debug.' :) Now that's thougths that I like :thumbsup: It's getting a little late in the evening here, so I'll have to try it tomorrow morning. But it seems you like you know the "little thing" I need to change
-
Does this help?
public static List Test()
{
// Create the proxy
MaintenanceService svc = new MaintenanceService();
svc.InnerChannel.OperationTimeout = new TimeSpan (1, 0, 0); // 1 hr timeout!// Get results List ret = svc.GetAssignments().ToList(); Debug.Assert (ret != null); // Return a separate list List assignments = new List(); foreach (Assignment a in ret) { assignments.Add (a); } return assignments;
}
/ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
Thanks. I couldn't find InnerChanel on the svc, so I'll see if I can find another way around it.
-
Thanks. I couldn't find InnerChanel on the svc, so I'll see if I can find another way around it.
Crap - I forgot you're using the CF. The property may be missing for that version of .NET. /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com