Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Wierd exceptions when calling WCF more than once from a static class

Wierd exceptions when calling WCF more than once from a static class

Scheduled Pinned Locked Moved C#
csharphelpquestionvisual-studiowcf
11 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Michael9000

    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 here

    The 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?

    R Offline
    R Offline
    Ravi Bhavnani
    wrote on last edited by
    #2

    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

    M 1 Reply Last reply
    0
    • R Ravi Bhavnani

      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

      M Offline
      M Offline
      Michael9000
      wrote on last edited by
      #3

      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) ?

      R 2 Replies Last reply
      0
      • M Michael9000

        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) ?

        R Offline
        R Offline
        Ravi Bhavnani
        wrote on last edited by
        #4

        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

        M 1 Reply Last reply
        0
        • M Michael9000

          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) ?

          R Offline
          R Offline
          Ravi Bhavnani
          wrote on last edited by
          #5

          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

          M 1 Reply Last reply
          0
          • R Ravi Bhavnani

            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

            M Offline
            M Offline
            Michael9000
            wrote on last edited by
            #6

            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;
            }
            }

            R 1 Reply Last reply
            0
            • M Michael9000

              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;
              }
              }

              R Offline
              R Offline
              Ravi Bhavnani
              wrote on last edited by
              #7

              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

              M 2 Replies Last reply
              0
              • R Ravi Bhavnani

                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

                M Offline
                M Offline
                Michael9000
                wrote on last edited by
                #8

                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

                1 Reply Last reply
                0
                • R Ravi Bhavnani

                  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

                  M Offline
                  M Offline
                  Michael9000
                  wrote on last edited by
                  #9

                  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

                  1 Reply Last reply
                  0
                  • R Ravi Bhavnani

                    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

                    M Offline
                    M Offline
                    Michael9000
                    wrote on last edited by
                    #10

                    Thanks. I couldn't find InnerChanel on the svc, so I'll see if I can find another way around it.

                    R 1 Reply Last reply
                    0
                    • M Michael9000

                      Thanks. I couldn't find InnerChanel on the svc, so I'll see if I can find another way around it.

                      R Offline
                      R Offline
                      Ravi Bhavnani
                      wrote on last edited by
                      #11

                      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

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups