Calling a remote object from a remote object.


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 10 of 10

Thread: Calling a remote object from a remote object.

  1. #1
    o11011 Guest

    Calling a remote object from a remote object.

    How do you call a remote object from an other remote object. When I try and
    used is as a client I get an exception and when I just created it as new it
    gives me a new instance even though its setup as a singleton. By the way its
    in the same assmebly. Thoughts?

    Thanks.



  2. #2
    Michael Welch Guest

    Re: Calling a remote object from a remote object.


    o11011,

    >How do you call a remote object from an other remote object. When I try



    I'll need more information to be able to help you.

    1. Are you using RemotingConfiguration.RegisterWellKnownServiceType to publish
    each of your remote objects as Singletons. If not, what are you doing?

    2. Are you registering a channel for each object using ChannelServices.RegisterChannel()

    3. How are you accessing the objects on the client side? Are you using
    Activator.GetObject? or are you using RemotingConfiguration.RegisterWellKnownClientType
    and the new keyword?

    4. What exactly is your problem? Are you having compile time errors? or
    runtime errors?

    Go ahead and post the server code you use to publish the objects and the
    client code you use to access the remote objects.

    Michael



  3. #3
    o11011 Guest

    Re: Calling a remote object from a remote object.

    inline response.

    "Michael Welch" <billshewman@hotmail.com> wrote in message
    news:3c963ac4$1@10.1.10.29...
    >
    > o11011,
    >
    > >How do you call a remote object from an other remote object. When I try

    >
    >
    > I'll need more information to be able to help you.
    >
    > 1. Are you using RemotingConfiguration.RegisterWellKnownServiceType to

    publish
    > each of your remote objects as Singletons. If not, what are you doing?
    >

    Yes

    > 2. Are you registering a channel for each object using

    ChannelServices.RegisterChannel()
    >

    Yes on the server well as the client, and that works just fine its only when
    I try to call the remote object from an other remote object in the same
    assembly.

    > 3. How are you accessing the objects on the client side? Are you using
    > Activator.GetObject? or are you using

    RemotingConfiguration.RegisterWellKnownClientType
    > and the new keyword?
    >

    From the client I am using
    RemotingConfiguration.RegisterWellKnownClientType. As for the other remote
    class when I try and use RemotingConfiguration.RegisterWellKnownClientType I
    get a remoting exception. So my question is how do I call it?

    > 4. What exactly is your problem? Are you having compile time errors? or
    > runtime errors?
    >

    I don't know how I am suppose to call a remote object from another remote
    object that is in the same dll. Does this help?

    > Go ahead and post the server code you use to publish the objects and the
    > client code you use to access the remote objects.
    >

    I am not at my machine so I can't post the code now.

    > Michael
    >
    >




  4. #4
    Michael Welch Guest

    Re: Calling a remote object from a remote object.


    o11011,

    >>

    >I don't know how I am suppose to call a remote object from another remote
    >object that is in the same dll. Does this help?
    >


    It should be like any other call. It shouldn't matter that they are both
    remote objects. I've done it lots of times. I haven't done it when they are
    both in the same assembly but I don't think that should make a difference,
    either.

    Without the code, I guess I don't know enough to even make a guess. I'd make
    sure that you are not trying to use the same port for each object, but I'm
    pretty sure that would give you a different and obvious exception.

    I'd double check the url you are using to access each object. Are you using
    tcp? The format should be

    tcp://serverort/uri

    or

    tcp://serverort/applicationname/uri (if you configured an application name).

    where uri is the uri you used to publish your object.

    I'd need to know more about the exception. If you can post the exact exception
    message that might help.

    Thanks,
    Michael

  5. #5
    o11011 Guest

    Re: Calling a remote object from a remote object.

    ok here you go.

    REMOTE OBJECT 1
    =========================================
    namespace RemoteObjectLibrary{
    public class RemoteObject : MarshalByRefObject{
    private long counter;
    public RemoteObject(){
    Console.Write("RemoteObject constructor called\n");
    }
    ~RemoteObject(){
    Console.Write("RemoteObject destructor called\n");
    }
    public string Greeting(string name){
    counter++;
    Console.Write("ThreadID: " + AppDomain.GetCurrentThreadId().ToString() +
    '\n');
    Console.Write("# of calls: " + counter.ToString() + '\n');
    return "Hello " + name;
    }
    }
    }

    REMOTE OBJECT 2
    =========================================
    namespace RemoteObjectLibrary{
    public class ROCaller : MarshalByRefObject{
    public ROCaller(){
    Console.Write("ROCaller constructor called\n");
    }
    ~ROCaller(){
    Console.Write("ROCaller destructor called\n");
    }
    public void CallIt(){

    RemoteObject obj = new RemoteObject();
    if(obj != null){
    for(int i = 0; i < 10; i++){
    obj.Greeting("Testing");
    }
    }
    }
    }
    }

    SERVER
    ========================================
    namespace RemoteObjectServer{
    class ROServer{
    [STAThread]
    static void Main(string[] args){
    //Register channel
    TcpServerChannel channel = new TcpServerChannel(8086);
    ChannelServices.RegisterChannel(channel);
    //Register CAO
    RemotingConfiguration.ApplicationName = "RemoteObjectLibrary";
    RemotingConfiguration.RegisterActivatedServiceType(typeof(RemoteObject));
    RemotingConfiguration.RegisterActivatedServiceType(typeof(ROCaller));
    //Register Singletons
    /*RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject),
    "RemoteObject",
    WellKnownObjectMode.Singleton);
    RemotingConfiguration.RegisterWellKnownServiceType(typeof(ROCaller),
    "ROCaller",
    WellKnownObjectMode.Singleton);*/
    Console.Write("hit any key to exit");
    Console.ReadLine();
    }
    }
    }

    CLIENT
    ========================================
    namespace RemoteObjectClient{
    class ROClient{
    [STAThread]
    static void Main(string[] args){
    //Register channel
    ChannelServices.RegisterChannel(new TcpClientChannel());
    //Register CAO
    RemotingConfiguration.RegisterActivatedClientType(typeof(ROCaller),
    "tcp://localhost:8086");
    //Register singleton
    //RemotingConfiguration.RegisterWellKnownClientType(typeof(ROCaller),
    "tcp://localhost:8086/ROCaller");
    ROCaller obj = new ROCaller();
    if(obj != null){
    obj.CallIt();
    Console.ReadLine();
    obj.CallIt();
    }
    }
    }
    }


    "Michael Welch" <billshewman@hotmail.com> wrote in message
    news:3c9667d9$1@10.1.10.29...
    >
    > o11011,
    >
    > >>

    > >I don't know how I am suppose to call a remote object from another remote
    > >object that is in the same dll. Does this help?
    > >

    >
    > It should be like any other call. It shouldn't matter that they are both
    > remote objects. I've done it lots of times. I haven't done it when they

    are
    > both in the same assembly but I don't think that should make a difference,
    > either.
    >
    > Without the code, I guess I don't know enough to even make a guess. I'd

    make
    > sure that you are not trying to use the same port for each object, but I'm
    > pretty sure that would give you a different and obvious exception.
    >
    > I'd double check the url you are using to access each object. Are you

    using
    > tcp? The format should be
    >
    > tcp://serverort/uri
    >
    > or
    >
    > tcp://serverort/applicationname/uri (if you configured an application

    name).
    >
    > where uri is the uri you used to publish your object.
    >
    > I'd need to know more about the exception. If you can post the exact

    exception
    > message that might help.
    >
    > Thanks,
    > Michael




  6. #6
    Michael Welch Guest

    Re: Calling a remote object from a remote object.


    o11011,

    I took a stab at it with the code you posted. I missed your note that they
    were both in the same assembly. I can't get it to work when they are both
    in the same assembly. I get channel tcp already registered message on a RemotingException.

    However, I don't understand why you need to use remoting to create an object
    in the same assembly.

    I can't think of when that would be necessary.

    "o11011" <o11011@hotmail.com> wrote:
    >How do you call a remote object from an other remote object. When I try

    and
    >used is as a client I get an exception and when I just created it as new

    it
    >gives me a new instance even though its setup as a singleton. By the way

    its
    >in the same assmebly. Thoughts?
    >
    >Thanks.
    >
    >

    Michael

  7. #7
    Michael Welch Guest

    Re: Calling a remote object from a remote object.


    o11011,


    "o11011" <o11011@hotmail.com> wrote:
    >How do you call a remote object from an other remote object. When I try

    and
    >used is as a client I get an exception and when I just created it as new

    it
    >gives me a new instance even though its setup as a singleton. By the way

    its
    >in the same assmebly. Thoughts?
    >


    I broke your code into two assemblies. Then I realized the problem. You
    are using a TcpServerChannel, when what you need is a TcpChannel. The TcpServerChannel
    can only listen, it can't make outgoing calls. That's why your client can
    call remote object 1 and remote object 1 can't call out to remote object
    2.

    Michael

    ps. I'll post some code that I used. I still don't know if I can make it
    work in one assembly, or why you would do that.


  8. #8
    Michael Welch Guest

    Re: Calling a remote object from a remote object.


    o11011,

    I've never used RegisterActivatedServiceType so I wrote the code the way
    I'm used to doing it. I could call one remote object from another even in
    the same assembly.

    I had to create one other assembly for the IROCaller interface. That is because
    the client needs an interface for ROCaller and you can't (as far as I know)
    make a reference to the exe assembly. Perhaps RegisterActivateServiceType
    gets around that problem, I don't know.

    I used RegisterWellKnownServiceType on server and Activator.GetObject on
    client.

    namespace RemoteObjectInterfaces
    {
    public interface IROCaller
    {
    void CallIt();
    }
    }

    Here is RemoteObject 1

    namespace RemoteObjectLibrary
    {
    public class RemoteObject : MarshalByRefObject
    {
    private long counter;
    public RemoteObject()
    {
    Console.Write("RemoteObject constructor called\n");
    }
    ~RemoteObject()
    {
    Console.Write("RemoteObject destructor called\n");
    }
    public string Greeting(string name)
    {
    counter++;
    Console.Write("ThreadID: " + AppDomain.GetCurrentThreadId().ToString()
    +
    '\n');
    Console.Write("# of calls: " + counter.ToString() + '\n');
    return "Hello " + name;
    }
    }
    }

    Remote Object #2

    namespace RemoteObjectLibrary
    {
    public class ROCaller : MarshalByRefObject, IROCaller
    {
    public ROCaller()
    {
    Console.Write("ROCaller constructor called\n");
    }
    ~ROCaller()
    {
    Console.Write("ROCaller destructor called\n");
    }
    public void CallIt()
    {

    RemoteObject obj = (RemoteObject) Activator.GetObject(
    typeof(RemoteObject),
    "tcp://localhost:8086/RemoteObjectLibrary/RemoteObject");

    if(obj != null)
    {
    for(int i = 0; i < 10; i++)
    {
    obj.Greeting("Testing");
    }
    }
    }
    }
    }

    CLIENT

    namespace RemoteObjectClient
    {
    class ROClient
    {
    [STAThread]
    static void Main(string[] args)
    {

    IROCaller obj = (IROCaller) Activator.GetObject(
    typeof(IROCaller),
    "tcp://localhost:8086/RemoteObjectLibrary/ROCaller");
    if(obj != null)
    {
    obj.CallIt();
    Console.ReadLine();
    obj.CallIt();
    }
    }
    }
    }

    I hope that helps you. biggest thing I found is that you used TcpServerChannel
    (one way communication) vs. TcpChannel (two way communication).

    Michael

  9. #9
    Michael Welch Guest

    Re: Calling a remote object from a remote object.


    "Michael Welch" <billshewman@hotmail.com> wrote:
    >
    >o11011,
    >
    >I've never used RegisterActivatedServiceType so I wrote the code the way
    >I'm used to doing it. I could call one remote object from another even in
    >the same assembly.
    >


    Here is the output:

    hit any key to exitROCaller constructor called
    RemoteObject constructor called
    ThreadID: 2540
    # of calls: 1
    ThreadID: 2540
    # of calls: 2
    ThreadID: 2540
    # of calls: 3
    ThreadID: 2540
    # of calls: 4
    ThreadID: 2540
    # of calls: 5
    ThreadID: 2540
    # of calls: 6
    ThreadID: 2540
    # of calls: 7
    ThreadID: 2540
    # of calls: 8
    ThreadID: 2540
    # of calls: 9
    ThreadID: 2540
    # of calls: 10

    Michael

  10. #10
    o11011 Guest

    Re: Calling a remote object from a remote object.

    Thank you so very much.

    "Michael Welch" <billshewman@hotmail.com> wrote in message
    news:3c97b8f1$1@10.1.10.29...
    >
    > "Michael Welch" <billshewman@hotmail.com> wrote:
    > >
    > >o11011,
    > >
    > >I've never used RegisterActivatedServiceType so I wrote the code the way
    > >I'm used to doing it. I could call one remote object from another even in
    > >the same assembly.
    > >

    >
    > Here is the output:
    >
    > hit any key to exitROCaller constructor called
    > RemoteObject constructor called
    > ThreadID: 2540
    > # of calls: 1
    > ThreadID: 2540
    > # of calls: 2
    > ThreadID: 2540
    > # of calls: 3
    > ThreadID: 2540
    > # of calls: 4
    > ThreadID: 2540
    > # of calls: 5
    > ThreadID: 2540
    > # of calls: 6
    > ThreadID: 2540
    > # of calls: 7
    > ThreadID: 2540
    > # of calls: 8
    > ThreadID: 2540
    > # of calls: 9
    > ThreadID: 2540
    > # of calls: 10
    >
    > Michael




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center