Re: Windows Service Remoting Question

From: Chris Q. (ChrisQ_at_discussions.microsoft.com)
Date: 10/27/04


Date: Wed, 27 Oct 2004 08:19:16 -0700

Ken,

I really appreciate your help. Once I removed the TCPListener.StartListening
and TCPListerner.StopListening methods everything began working perfectly.
Thank you so much! This has been a 14 hours stumbling block for me.

I did included the registration of the objects in the OnStart method because
all the examples I have seen do this. However, the same examples show a call
to the StartListening and StopListening methods.

Later!
Chris

"Ken Kolda" wrote:

> The first problem I see is that you should not be calling the
> StartListening() method on the TCPListener object. The remoting framework
> will take care of that for you. What I'm guessing is that when you call this
> an exception occurs and it calls OnStop() (which, I'm guessing, stops the
> TCPListener from listening). Why you don't see anything in the event log I'm
> not sure. Do you see the "Application Server Registered" entry in the log
> after the remote object is registered?
>
> Also, you don't show this but I assume this code is on the OnStart() method
> of the service class (which is good). If not, you should either put it there
> or somewhere else you can ensure will only run once.
>
> Ken
>
>
> "Chris Q." <ChrisQ@discussions.microsoft.com> wrote in message
> news:CAF9682A-C592-4FDE-BB1D-9199DA588284@microsoft.com...
> > The service is written to write notification events into the application
> > event log, and there are no events indicating that the service is not
> > running. I'm using Try...Catch blocks to write events to the log if any
> > problems occur.
> >
> > Here is the working console server:
> > Sub Main()
> > Dim TCPListener As TcpChannel
> > TCPListener = New TcpChannel(2550)
> > ChannelServices.RegisterChannel(TCPListener)
> >
> > Try
> > RemotingConfiguration.ApplicationName = "ResumeServer"
> >
> >
> RemotingConfiguration.RegisterWellKnownServiceType(GetType(ApplicantServer),
> > "applicants.rem", WellKnownObjectMode.SingleCall)
> > Configuration.WriteEvent("Applicant Server Registered",
> > EventLogEntryType.Information, 50090)
> > Catch rex As RemotingException
> > Configuration.WriteEvent(rex.Message, EventLogEntryType.Error,
> > 50010)
> > Catch ex As Exception
> > Configuration.WriteEvent(ex, EventLogEntryType.Error, 50000)
> > End Try
> >
> > Try
> > TCPListener.StartListening(Nothing)
> > Configuration.WriteEvent("The Resumè server is listening on
> port
> > 2550" & vbCrLf & URLList.ToString, EventLogEntryType.Information, 0)
> > Catch ex As Exception
> > Configuration.WriteEvent(ex, EventLogEntryType.Error, 50020)
> > End Try
> > Console.ReadLine()
> > TCPListener.StopListening(Nothing)
> > End Sub
> >
> > Here is the working console client:
> > Sub Main()
> > Dim ServerClient As TFF.ResumeManager.IApplicant =
> > Activator.GetObject(GetType(TFF.ResumeManager.IApplicant),
> > "http://localhost:2550/ResumeServer/applicants.rem")
> >
> > Try
> > Dim ApplicantList As DataSet =
> > ServerClient.LoadApplicantList(True)
> > Console.WriteLine(ApplicantList.ToString())
> > Catch ex As System.Net.Sockets.SocketException
> > Console.WriteLine(ex.Message)
> > Console.WriteLine(ex.StackTrace)
> > Catch ex As System.Net.WebException
> > Console.WriteLine(ex.Message)
> > Console.WriteLine(ex.StackTrace)
> > Catch ex As Exception
> > Console.WriteLine(ex.Message)
> > Console.WriteLine(ex.StackTrace)
> > End Try
> > Console.ReadLine()
> > End Sub
> >
> > Here is the service that is not currently working:
> > TCPListener = New HttpChannel(2550)
> > ChannelServices.RegisterChannel(TCPListener)
> >
> > Try
> > RemotingConfiguration.ApplicationName = "ResumeServer"
> >
> >
> RemotingConfiguration.RegisterWellKnownServiceType(GetType(ApplicantServer),
> > "applicants.rem", WellKnownObjectMode.SingleCall)
> > ServerUtility.WriteEvent("Applicant Server Registered",
> > EventLogEntryType.Information, 50090)
> > Catch rex As RemotingException
> > ServerUtility.WriteEvent("Line 76",
> EventLogEntryType.Information)
> > ServerUtility.WriteEvent(rex.Message, EventLogEntryType.Error,
> > 50010)
> > Catch ex As Exception
> > ServerUtility.WriteEvent("Line 78",
> EventLogEntryType.Information)
> > ServerUtility.WriteEvent(ex, EventLogEntryType.Error, 50000)
> > Finally
> > Me.OnStop()
> > End Try
> >
> > Try
> > TCPListener.StartListening(Nothing)
> > ServerUtility.WriteEvent("The Resumè server is listening on
> port
> > 2550" & vbCrLf & URLList.ToString, EventLogEntryType.Information, 0)
> > Catch ex As Exception
> > ServerUtility.WriteEvent("Line 96",
> EventLogEntryType.Information)
> > ServerUtility.WriteEvent(ex, EventLogEntryType.Error, 50020)
> > OnStop()
> > End Try
> >
> > The activator on the client works fine until I call a method on the
> remoting
> > object which is inheriting from MarshalByRef. I get a null reference from
> the
> > service server. I get a dataset from the console server.
> >
> > Thanks for any assistance.
> >
> > "Ken Kolda" wrote:
> >
> > > A few questions/comments:
> > >
> > > 1) Does your service start and stay running or does it terminate
> immediately
> > > after starting?
> > > 2) Assuming the service starts, can you connect to the port it's using
> via
> > > telnet to verify the server is listening for connections?
> > > 3) You must be getting some kind of exception, either from the server or
> > > from the client when you attempt to connect. Can you post that in its
> > > entirety?
> > >
> > > If you could post the code of your service class, that would help too.
> Don't
> > > post all your code -- just the class that derives from ServiceBase and
> only
> > > the code that registers the channel and any remoting objects.
> > >
> > > Ken
> > >
> > >
> > > "Chris Q." <ChrisQ@discussions.microsoft.com> wrote in message
> > > news:B7C9538A-992A-4CDF-843F-7099819DFEE9@microsoft.com...
> > > > I am designing a client/server application that will utilize remoting.
> I
> > > am
> > > > able to get things working without a problem using console
> applications,
> > > but
> > > > when I desire to create a windows service, I get all kinds of
> errors...
> > > none
> > > > of which are traceable.
> > > >
> > > > This is how I began the process. I first created the console server
> and
> > > the
> > > > console client. I verified that they are working properly with both
> TCP
> > > > channels and HTTP channels. However, when I take the exact same code
> and
> > > > place it into a windows service, I get no-descriptive errors and
> > > > connectionsink problems.
> > > >
> > > > I'm using well known single call objects on the server. The idea is to
> > > > contact the server to retrieve or save a dataset. This works
> beautifully
> > > with
> > > > the console apps either on a single machine or on seperate machines.
> > > However,
> > > > when I attempt to do the same task in a windows service on seperate
> > > machines,
> > > > I get the errors.
> > > >
> > > > Anyone run into similar problems?
> > > >
> > > > Thanks!
> > >
> > >
> > >
>
>
>



Relevant Pages

  • Re: Max number of items in a listbox?
    ... >> ListBox as sort of an event log. ... >> limiting the number of entries that can accumulate in this listbox ... >Sub AddLogEntry ...
    (microsoft.public.vb.general.discussion)
  • Write log description
    ... Private Sub Page_Load(ByVal sender As System.Object, ... Sub WriteToEventLog(ByVal LogName As String, ... 'Create event log if it doesn't exist ...
    (microsoft.public.dotnet.general)
  • Re: Windows Services
    ... Public Class MyService ... End Sub ... Note EventLog is inherited from ServiceBase and will be the normal event log ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Windows Service installed but not working???
    ... Are you doing too much work in the OnStart method? ... End Sub ... Note EventLog is inherited from ServiceBase and will be the normal event log ... Tell me how do you debug smething like this if you have to ...
    (microsoft.public.dotnet.languages.vb)
  • CPU Upgrade?
    ... sub vendor ID 0x1043 ... designation DIMM 1 ... DMI Port Connector ... port type USB ...
    (uk.comp.homebuilt)