Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Remoting / October 2003

Tip: Looking for answers? Try searching our database.

Hosting Remote Object - Again

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David Steigerwald - 28 Oct 2003 18:09 GMT
This question seems to come up about every other day, and so far has only
been answered once and I didn't understand the answer.

I, too, need to access the remoting object at the server.  I am creating a
singleton object to hold a stack of information in memory, provided by
various clients which add records to the stack.  The server needs to
periodically access the stack to process and delete the entries.

Here is the code I am using to instantiate the object on both client and
server:

Dim args() As Object

_mSCredentials =
CType(Activator.CreateInstance(GetType(RemotingServer.SingletonCredentials),
args), RemotingServer.SingletonCredentials)

The problem is, the object created on the server is not the same instance as
the object on the clients: they both work fine, but they don't see each
other.

I am setting up these objects based on the app.config file, which has
entries like this on the server:

<configuration>
  <system.runtime.remoting>
     <application>
        <service>
            <wellknown
              type="RemotingServer.SingletonCredentials,RemoteCredentials"
              objectUri="SingletonCredentials"
              mode="Singleton"
           />
        </service>
        <channels>
  <channel ref="tcp" port="8080">
   <serverProviders>
    <formatter ref="binary"/>
   </serverProviders>
  </channel>
        </channels>
     </application>
  </system.runtime.remoting>
</configuration>

And this one on the client:

<configuration>
  <system.runtime.remoting>
     <application>
        <client url="tcp://localhost:8080">
        <wellknown
   type="RemotingServer.SingletonCredentials,RemoteCredentials"
   url="tcp://localhost:8080/SingletonCredentials"
   />
     </client>
    </application>
  </system.runtime.remoting>
</configuration>

This is all based on the Microsoft Remoting sample code.  What do I need to
change?

Signature

David Steigerwald

Sunny - 28 Oct 2003 18:35 GMT
Hi David,

> This question seems to come up about every other day, and so far has only
> been answered once and I didn't understand the answer.
[quoted text clipped - 16 lines]
> the object on the clients: they both work fine, but they don't see each
> other.

I'd suggest to create the stack at server, and to provide methods and/or
properties to access it from the client. Also, make it sure that
Activator.CreateInstance is not creating a local copy, it happens if
something in the config is not correct. You may add some kind of logging
at server side, just to see if when a call is made at client, it is
passed to the server.

Hope that helps
Sunny
David Steigerwald - 28 Oct 2003 19:55 GMT
Sonny, Thanks for responding.  I am pretty sure the server is creating a
local copy (why doesn't it give you an error message when that happens?),
but I am afraid my understanding is not where it needs to be to figure out
how to correct the problem.

> > Here is the code I am using to instantiate the object on both client and
> > server:
> >
> > Dim args() As Object
> >
> > _mSCredentials =

CType(Activator.CreateInstance(GetType(RemotingServer.SingletonCredentials),
> > args), RemotingServer.SingletonCredentials)

Given that I am using the same code in both places, it seems likely that the
config file should be the same in both places in order to work.  However, I
have to configure the server AND client on the host, and the client and
server configuration files are different.  I tried adding the client setup
to the host config file, but I can't a open port more than once.  I guess
one way to do it is to use two separate applications on the server, but is
that the only way?

> I'd suggest to create the stack at server, and to provide methods and/or
> properties to access it from the client. Also, make it sure that
[quoted text clipped - 5 lines]
> Hope that helps
> Sunny
Sunny - 28 Oct 2003 21:45 GMT
Hi David,

> Sonny, Thanks for responding.  I am pretty sure the server is creating a
> local copy (why doesn't it give you an error message when that happens?),
[quoted text clipped - 10 lines]
> CType(Activator.CreateInstance(GetType(RemotingServer.SingletonCredentials),
> > > args), RemotingServer.SingletonCredentials)

I'm missing something. Why do you call CreateInstance at the server?

To access that object from server, you may creat an istanse with "new"
keyword, and after that Marshal that object to the remoting system. The
code at server should be something like:

string objectUri = "SingletonCredentials.rem";
 //you may use .soap vs .rem

SingletonCredentials myServerObj = new SingletonCredentials();
RemotingServices(myServerObj, objectUri);

You have to remove from the config file the <service> section, and leave
only the <channels>.

In that way you still cann access that object from the servers code
referencing myServerObj, and from the clients, using:

RemotingServer.SingletonCredentials _mSCredentials = new    
    RemotingServer.SingletonCredentials;

And the clients config shuod look like:

<configuration>
  <system.runtime.remoting>
     <application>
        <client url="tcp://localhost:8080">
        <wellknown
   type="RemotingServer.SingletonCredentials,RemoteCredentials"
   url="tcp://localhost:8080/SingletonCredentials.rem"
   />
     </client>
    </application>
  </system.runtime.remoting>
</configuration>

So, in that way you cann access one and the same object from client and
server. From server you will use myServerObject.DoSomething()
and from client: _mSCredentials.DoSomething()

The above coed is in C#, but you can easily translate it in VB

Hope this helps
Sunny
David Steigerwald - 29 Oct 2003 15:08 GMT
I figured this out after writing that last email, and in fact did exactly
what you suggested.  I was just getting ready to document it for the group,
but you saved me the effort!

Thanks for all your help!  I had about given up on this group, but thanks to
you it is working (to stretch the United Way theme here).  Perhaps the
reason so many questions go unanswered is a matter of not making the request
specific enough.  I put in 3 questions, but the one that got a response was
the one I included a complete description of what I was doing and code
snippets.

I'm missing something. Why do you call CreateInstance at the server?

> To access that object from server, you may creat an istanse with "new"
> keyword, and after that Marshal that object to the remoting system. The
[quoted text clipped - 5 lines]
> SingletonCredentials myServerObj = new SingletonCredentials();
> RemotingServices(myServerObj, objectUri);
Sunny - 29 Oct 2003 15:44 GMT
> I figured this out after writing that last email, and in fact did exactly
> what you suggested.  I was just getting ready to document it for the group,
[quoted text clipped - 6 lines]
> the one I included a complete description of what I was doing and code
> snippets.

Yes, people think differently :)
No one can easily guess what you have in mind :)

Sunny
Sunny - 28 Oct 2003 22:09 GMT
Sorry, I have typo at the prev. post.
The right line at server code is:

RemotingServices.Marshal(myServerObj, objectUri);

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.