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. WCF Connection

WCF Connection

Scheduled Pinned Locked Moved C#
helpcsharpwcfquestion
6 Posts 4 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.
  • C Offline
    C Offline
    cdpace
    wrote on last edited by
    #1

    Hello everyone,

    ActiveDB.DBContractsClient _Proxy = new ActiveDB.DBContractsClient();

            \_Proxy.Open();
    
            \_Proxy.ExecuteQuery("Select 1", new object\[\] { });
    
            \_Proxy.Close();
    
            \_Proxy.Open();
          \_Proxy.Close();
    

    I have the following code to demonstrate my problem. Till the point where is the second open it works fine, but when it tries to open to connection for the second time it says cannot open object because it is disposed. Am I doing something worng or any ideas on how i may fix it? Thank you for any help.

    P P 2 Replies Last reply
    0
    • C cdpace

      Hello everyone,

      ActiveDB.DBContractsClient _Proxy = new ActiveDB.DBContractsClient();

              \_Proxy.Open();
      
              \_Proxy.ExecuteQuery("Select 1", new object\[\] { });
      
              \_Proxy.Close();
      
              \_Proxy.Open();
            \_Proxy.Close();
      

      I have the following code to demonstrate my problem. Till the point where is the second open it works fine, but when it tries to open to connection for the second time it says cannot open object because it is disposed. Am I doing something worng or any ideas on how i may fix it? Thank you for any help.

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      It looks like _Proxy.Close automatically disposes of the object. I'd take a look into that if I were you. One way round it is to create a new instance of ActiveDB.DBContractsClient before calling the second _Proxy.Open.

      I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

      Forgive your enemies - it messes with their heads

      My blog | My articles | MoXAML PowerToys | Onyx

      C 1 Reply Last reply
      0
      • P Pete OHanlon

        It looks like _Proxy.Close automatically disposes of the object. I'd take a look into that if I were you. One way round it is to create a new instance of ActiveDB.DBContractsClient before calling the second _Proxy.Open.

        I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

        Forgive your enemies - it messes with their heads

        My blog | My articles | MoXAML PowerToys | Onyx

        C Offline
        C Offline
        cdpace
        wrote on last edited by
        #3

        The Issue is that I want to use the same instance i am using this in a web application and what I am doing is that I am creating this instance when the session starts and use the same instance for every operation that the user does in the application. And for every operation I want to open and close the connection to make sure that no connections are ever left open.

        P J 2 Replies Last reply
        0
        • C cdpace

          The Issue is that I want to use the same instance i am using this in a web application and what I am doing is that I am creating this instance when the session starts and use the same instance for every operation that the user does in the application. And for every operation I want to open and close the connection to make sure that no connections are ever left open.

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          You can't have it both ways unfortunately. Either it's disposed and you create a new instance every time, or you have to leave it open. It would be easier if you had control of the class itself, and could remove the Dispose out of there, but it looks like you don't have that option.

          I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

          Forgive your enemies - it messes with their heads

          My blog | My articles | MoXAML PowerToys | Onyx

          1 Reply Last reply
          0
          • C cdpace

            Hello everyone,

            ActiveDB.DBContractsClient _Proxy = new ActiveDB.DBContractsClient();

                    \_Proxy.Open();
            
                    \_Proxy.ExecuteQuery("Select 1", new object\[\] { });
            
                    \_Proxy.Close();
            
                    \_Proxy.Open();
                  \_Proxy.Close();
            

            I have the following code to demonstrate my problem. Till the point where is the second open it works fine, but when it tries to open to connection for the second time it says cannot open object because it is disposed. Am I doing something worng or any ideas on how i may fix it? Thank you for any help.

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            I was playing with WCF last spring, not with a web whatsis, and only opened the connection once, so I didn't encounter that. I'll take a look at what I can find out later.

            1 Reply Last reply
            0
            • C cdpace

              The Issue is that I want to use the same instance i am using this in a web application and what I am doing is that I am creating this instance when the session starts and use the same instance for every operation that the user does in the application. And for every operation I want to open and close the connection to make sure that no connections are ever left open.

              J Offline
              J Offline
              jschell
              wrote on last edited by
              #6

              cdpace wrote:

              ...and use the same instance for every operation that the user does in the application

              And why do you want to do that? What benefit do you think that you get from that?

              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