By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,965 Members | 1,631 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,965 IT Pros & Developers. It's quick & easy.

Using SimpleXMLRPCServer in a Windows Service

P: n/a
After some Googling I found a post of someone who wanted to do exactly
as what I want to do now.
There is however a problem in his code that makes the service fails
after the first connection. I slightly modified his code and now I can
run the service longer before I run into trouble.
I then tried making the SimpleXMLRPCServer multi-threaded, hoping the
problem would disappear, but no avail.
The code is as follows:
The commented part in the while loop is from the original code.
## XML-RPC Service
import sys
import win32serviceutil
import win32service
import win32event
import win32evtlogutil
import win32file
import servicemanager
import SimpleXMLRPCServer
import SocketServer
import select

class OBJECT:
def hello(self, text):
return "Hello World (%s)" % text

class ThreadedSimpleXMLRPCServer(SocketServer.ThreadingM ixIn,
SimpleXMLRPCServer.SimpleXMLRPCServer): pass

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

def __init__(self, args):
win32evtlogutil.AddSourceToRegistry(self._svc_disp lay_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)
self.stop_requested = 0

def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP _PENDING)
self.stop_requested = 1

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

server = ThreadedSimpleXMLRPCServer(("", 8080))
object = OBJECT()
self.socket = server.socket

while 1:
r, w, x =[self.socket],[],[],10)
if r == [self.socket]:
if self.stop_requested:
#rc =
win32event.WaitForMultipleObjects((self.hWaitStop, self.hSockEvent), 0,
#if rc == win32event.WAIT_OBJECT_0:
# break
# server.handle_request()
# win32file.WSAEventSelect(server,self.hSockEvent, 0)
# #server.serve_forever() ## Works, but breaks the

## Write a stopped event

if __name__ == '__main__':

I tested with the following:


import xmlrpclib
import time

server = xmlrpclib.ServerProxy("http://localhost:8080")
for i in range(100):
print server.hello("%d" % i)


The loop ends with the following error:

Hello World (0)
Hello World (44)
Traceback (most recent call last):
File "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\" ,
line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\DATA\", line 6, in ?
print server.hello("%d" % i)
File "C:\Python24\lib\", line 1096, in __call__
return self.__send(self.__name, args)
File "C:\Python24\lib\", line 1383, in __request
File "C:\Python24\lib\", line 1137, in request
ProtocolError: <ProtocolError for localhost:8080/RPC2: -1 >

Can someone help me in creating a windows service that allows me to
handle XMLRPC request?

Thanks in advance,

Rudy Schockaert
Nov 23 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.