SimpleXMLRPCServer runnning as a Windows Service using win32serviceutil



I am trying to create a Windows service using SimpleXMLRPCServer and
win32serviceutil. The service itself seems to be working properly
(starts, stops, etc) and I can connect using an XMLRPC client from the
localhost. However when I connect from a remote client, I either get a
socket error or an xmlrpclib.ProtocolError error. If I use
serve_forever() rather than handle_request(), the remote clients can
connect but it breaks the Windows service functionality (can't stop the
service). I have tried the same code without the service and that
works, both locally and remotely. It would seem that the problem is
related to the way the service handles remote connections, but I cannot
figure out what the problem is.

I have searched around, but can't find any example code. Hopefully
someone can point me in the right direction.

thanks,
John

## XML-RPC Service
import win32serviceutil
import win32service
import win32event
import win32evtlogutil
import win32file
import servicemanager
import SimpleXMLRPCServer

class OBJECT:
def hello(self):
return "Hello World"

class XMLRPCSERVICE(win32serviceutil.ServiceFramework):
_svc_name_ = "XMLRPCSERVICE"
_svc_display_name_ = "XMLRPCSERVICE"
_svc_description_ = "XMLRPCSERVICE"

def __init__(self, args):
win32evtlogutil.AddSourceToRegistry(self._svc_display_name_,
sys.executable, "Application")
win32serviceutil.ServiceFramework.__init__(self, args)

self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
self.hSockEvent = win32event.CreateEvent(None, 0, 0, None)

def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)

def SvcDoRun(self):
## Write a started event
servicemanager.LogMsg(
servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
(self._svc_name_, ' (%s)' % self._svc_name_))

server = SimpleXMLRPCServer.SimpleXMLRPCServer(("", 8080))
object = OBJECT()
server.register_instance(object)

while 1:
win32file.WSAEventSelect(server,
self.hSockEvent,win32file.FD_ACCEPT)
rc =
win32event.WaitForMultipleObjects((self.hWaitStop,self.hSockEvent), 0,
win32event.INFINITE)
if rc == win32event.WAIT_OBJECT_0:
break
else:
win32file.WSAEventSelect(server,self.hSockEvent, 0)
server.handle_request()
#server.serve_forever() ## Works, but breaks the
Windows service functionality

## Write a stopped event
win32evtlogutil.ReportEvent(self._svc_name_,

servicemanager.PYS_SERVICE_STOPPED,0,

servicemanager.EVENTLOG_INFORMATION_TYPE,
(self._svc_name_,""))

if __name__ == '__main__':
win32serviceutil.HandleCommandLine(XMLRPCSERVICE)

----------------------------------------------------------------
##XML-RPC Server without service, this works using handle_request()
import SimpleXMLRPCServer

#The server object
class OBJECT:
def hello(self):
return "Hello World"

object = OBJECT()
server = SimpleXMLRPCServer.SimpleXMLRPCServer(("", 8080))
server.register_instance(object)

#Go into the main listener loop
print "Listening on port 8080"
while 1:
server.handle_request()

----------------------------------------------------------------
## XML-RPC Client
import xmlrpclib

server = xmlrpclib.ServerProxy("http://remoteserver:8080";)
print server.hello()

.



Relevant Pages

  • Re: Looking For Code Sample and Request Feedback
    ... I would prefer to use a Windows Service but a web service will do to. ... What is very easy to do on a Server 2003 and with VBNet? ... > I am looking for a code sample that communicates from a client to a remote> Windows Service on another computer over the internet, that is the Windows> Service performing instructions the client sends. ... the client does the office automation and the actual> communication of the commands to this server. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Automatic startup of .NET server-side object?
    ... data from the client to the server, and I do not want to require a login ... before startup (I am using a console app in my prototyping). ... Does a Windows service have access to the local file system? ... > security/authentication of IIS ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Best architecture - upload file and save on different server
    ... port with a different set of credentials to the asp account. ... permissions to map to the remote server. ... So use a Windows service so authentication is not a problem?? ... Then use a windows service to FTP the file to server two ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Displaying a popup from a windows service using .NET remoting
    ... A Windows Service that acts as a remoting server. ... A client UI piece that launches with each login (i.e. in the same ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: SimpleXMLRPCServer and Threading
    ... The base SimpleXMLRPCServer uses TCPServer as it's server component ... The clients will ask for the next file. ... this with functions, but when you register an object in the server, ...
    (comp.lang.python)