473,513 Members | 3,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SimpleXMLRPCServer runnning as a Windows Service using win32serviceutil

JDF
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_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)

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()

Apr 26 '06 #1
0 1984

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
8020
by: D | last post by:
I have a simple file server utility that I wish to configure as a Windows service - using the examples of the Python Win32 book, I configured a class for the service, along with the main class...
1
442
by: rodmc | last post by:
Hello, I am trying to figure out how to write a windows service, I am totally new to it. I have written a simple test case, however it doesn't appear to do anything. Although it installs and...
0
1405
by: Rudy Schockaert | last post by:
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...
5
3934
by: momobear | last post by:
I feel really puzzled about fellowing code, please help me finger out what problem here. import threading class workingthread(threading.Thread): def __init__(self): self.quitEvent =...
0
7254
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7094
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.