Solved

Remoting problem

Posted on 2004-10-19
8
417 Views
Last Modified: 2008-01-09
Hi all,

I need to crate a two way communication between client and server using Remoting. I have a Dll file in which I keep two interfaces. Let's call them IA and IB. IA is implemented by the server's class A and IB is implemented by the client's class B.
The main goal is to send an object of type IB (an instance of B) that is created on the client, through a method on an object of type IA (an instance of A) theat is created by the server.

Well, the server exposes A using Remoting and the client receives it. The client can call methods and properties on A (easy, because it knows the interface IA) and even can pass the B object throgh a certain method. BUT, whenever I try to call a method on B (using the IB interface) I fail.

What am I doing wrong?

Here are Interfaces.cs, Client.cs, Server.cs and error description:

**********************Interfaces*********************
using System;

namespace Interfaces
{
      public interface IA
      {
            string Name
            {
                  get;
            }
            
            void SetClient(IB b);
            
      }      

      public interface IB
      {
            string Name
            {
                  get;
            }            
      }
}
*****************************************************

************************Server**********************
using System;
using System.Runtime.Remoting;

using Interfaces;


namespace Server
{
      [Serializable]
      class A: MarshalByRefObject, IA
      {
            [STAThread]
            static void Main(string[] args)
            {
                  RemotingConfiguration.Configure("RemotingListener.config");
                  Console.ReadLine();
            }            
            
            #region IA Members

            public string Name
            {
                  get { return "Server"; }
            }

            public void SetClient(IB b)
            {
                  Console.WriteLine(b.Name);
            }

            #endregion
      }
      
}
*****************************************************

************************Client**********************
using System;
using System.Runtime.Remoting;

using Interfaces;

namespace Client
{
      [Serializable]
      class B: MarshalByRefObject, IB
      {      
            [STAThread]
            static void Main(string[] args)
            {      
                  
                  RemotingConfiguration.Configure("ClientSideRegistrar.config");                  
                  IA a = (IA)Activator.GetObject(typeof(IA), "http://localhost:8989/A.rem");                                                

                  B b = new B();
                  a.SetClient(b);            

                  Console.ReadLine();
            }                        

            #region IB Members

            public string Name
            {
                  get
                  {
                        return "Client";
                  }
            }

            #endregion
      }
}

*****************************************************

************************Error description**********************
An unhandled exception of type 'System.Runtime.Remoting.RemotingException' occurred in mscorlib.dll

Additional information: System.ArgumentNullException: No message was deserialized prior to calling the DispatchChannelSink.
Parameter name: requestMsg
   at System.Runtime.Remoting.Channels.DispatchChannelSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)
   at System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)
   at System.Runtime.Remoting.Channels.Http.HttpServerTransportSink.ServiceRequest(Object state)
   at System.Runtime.Remoting.Channels.SocketHandler.ProcessRequestNow()
*******************************************************************


Ophir.
0
Comment
Question by:ophirg
8 Comments
 
LVL 3

Expert Comment

by:aacool
ID: 12347273
Can you post your config files as well?

0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 12347678
This is tricky, since it will allow the server to do remoting calls to the client, which in turn requires the client to be able to receive such calls. Make sure that your configuration is correct so that the server can also reach the client, and that the client listens correctly for server calls.
0
 
LVL 1

Author Comment

by:ophirg
ID: 12349538
Solved it by myself.

Thank you for your time, guys.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:aacool
ID: 12351995
That's not a very helpful question and solution - you had people waiting on your question, without an explanation what is wrong - Mods?
0
 
LVL 1

Author Comment

by:ophirg
ID: 12352231
I am sorry for the inconvenience. I will post the solution tomorrow morning when I am at work.

Ophir.
0
 
LVL 1

Author Comment

by:ophirg
ID: 12355401
Hello all,

The solution is in the config files. Notice how I registered both as a service and as a client:

******************************Server config******************************
<configuration>
      <system.runtime.remoting>
            <application>
                  <service>
                        <wellknown
                              mode="Singleton"
                              displayName = "A"
                              type="Server.A, Server"
                              objectUri="A.rem"
                        />
                  </service>
                  <client>
                        <wellknown
                              type="Interfaces.IB, Interfaces"
                              displayName="B"
                              url="http://localhost:8989/B.rem"
                        />
                  </client>
                  <channels>
                        <channel ref="http" port="8989">
                              <serverProviders>
                                    <formatter
                                          ref="binary"
                                          typeFilterLevel="Full"
                                    />
                              </serverProviders>
                              <clientProviders>
                                    <formatter ref="binary"/>                              
                              </clientProviders>
                        </channel>      
                  </channels>
            </application>
      </system.runtime.remoting>
</configuration>
*********************************************************************


******************************Client config******************************
<configuration>
   <system.runtime.remoting>
      <application>
         <client>
            <wellknown
               type="Interfaces.IA, Interfaces"
               displayName="A"
               url="http://localhost:8989/A.rem"
            />
         </client>
         <service>
                        <wellknown
                              mode="SingleCall"
                              displayName = "B"
                              type="Client.B, Client"
                              objectUri="B.rem"
                        />
                  </service>
         <channels>
                  <channel ref="http"      port="0">
                        <clientProviders>
                              <formatter ref="binary"/>                              
                        </clientProviders>
                        <serverProviders>
                              <formatter ref="binary" typeFilterLevel="Full"/>
                        </serverProviders>
                  </channel>                  
         </channels>
      </application>
   </system.runtime.remoting>
</configuration>

*********************************************************************



That is it. I will gladly read your comments on this subject.

Thank you all,
Ophir.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12632838
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now