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. Reconnecting to a remote server using DCOM

Reconnecting to a remote server using DCOM

Scheduled Pinned Locked Moved C#
sysadmincsharpcomhelptutorial
3 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.
  • B Offline
    B Offline
    bob2k_03
    wrote on last edited by
    #1

    Hello all, I am writing a client for a remote windows service using C#. I first instantiate the remote object ... Type t = Type.GetTypeFromProgID(progId, serverName); APPLib.IApp obj = (APPLib.IApp)Activator.CreateInstance(type); Then I use the method and it works great .. obj.SomeMethod(); But if I unplug the network cable between the object creation and its use, I get a 0x800706BF COMException (The remote procedure call failed.) which is expected. The problem I have is after I reconnect the network cable and then try to recover by calling the Type.GetTypeFromProgID() and Activator.CreateInstance(type) methods, I repeatedly get "The remote procedure call failed." COM Exceptions in the Activator.CreateInstance() call. I can even start another instance of my client that connects to the remote server just fine while this instance is still throwing execptions. Any suggestions on how to recover gracefully? Thank you, Bob

    M 1 Reply Last reply
    0
    • B bob2k_03

      Hello all, I am writing a client for a remote windows service using C#. I first instantiate the remote object ... Type t = Type.GetTypeFromProgID(progId, serverName); APPLib.IApp obj = (APPLib.IApp)Activator.CreateInstance(type); Then I use the method and it works great .. obj.SomeMethod(); But if I unplug the network cable between the object creation and its use, I get a 0x800706BF COMException (The remote procedure call failed.) which is expected. The problem I have is after I reconnect the network cable and then try to recover by calling the Type.GetTypeFromProgID() and Activator.CreateInstance(type) methods, I repeatedly get "The remote procedure call failed." COM Exceptions in the Activator.CreateInstance() call. I can even start another instance of my client that connects to the remote server just fine while this instance is still throwing execptions. Any suggestions on how to recover gracefully? Thank you, Bob

      M Offline
      M Offline
      Maxim Alekseykin
      wrote on last edited by
      #2

      use try/catch:laugh:

      B 1 Reply Last reply
      0
      • M Maxim Alekseykin

        use try/catch:laugh:

        B Offline
        B Offline
        bob2k_03
        wrote on last edited by
        #3

        Thank you for the suggestion and I apologize for not being clearer. I do use try/catch blocks. I am attempting to implement some retry logic to handle the occasional network glitch. The CreateObject() method in the code below wraps the Type.GetTypeFromProgID() and Activator.CreateInstance() calls. The CreateObject() method is also the method I call to intially create the remote object (crudq in this code). What I do to create this problem is set a breakpoint on the crudq.DatabaseQuery call. When the breakpoint is reached (and the remote object crudq is successfully created), I unplug the network cable and hit F10 to execute the call. The crudq.DatabaseQuery() throws a RPC_S_CALL_FAILED COMException. I then plug the network cable back in then F10 through the code. Every call to CreateObject() throws a RPC_S_CALL_FAILED COMException when it calls Activator.CreateInstance(). Below is the code: public void DatabaseQuery(string databaseName, int instance, Object input, Object filter, ref Object output, ref int result) { bool retry = true; int count = 0; int r = 0; Object o; do { try { crudq.DatabaseQuery(databaseName, instance, timeout, input, filter, out o, out r); retry = false; result = r; output = o; } catch(COMException c) { if (count < retryAttempts && (c.ErrorCode == RPC_S_CALL_FAILED || c.ErrorCode == RPC_S_SERVER_UNAVAILABLE)) { x.Info("DatabaseQuery: Retry count: " + count.ToString() + ", Exception: " + c.Message); Thread.Sleep(delayBetweenRetry); //Recreate COM object Object obj; try { CreateObject(progID, server, out obj); crudq = (AMSLib.ICRUDQ)obj; } catch { } ++count; } else { x.Error("DatabaseQuery: Exception caught: " + c.Message, c); throw; } } catch(Exception e) { x.Error("DatabaseQuery: Exception caught: " + e.Message, e); throw; } } while(retry); } Thank you, Bob

        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