Solved

Remoting problem

Posted on 2004-10-19
8
416 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 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

18 Experts available now in Live!

Get 1:1 Help Now