<br><font size=2 face="sans-serif">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). 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. </font>
<br>
<br><font size=2 face="sans-serif">I have searched around, but can't find
any example code. Hopefully someone can point me in the right direction.</font>
<br>
<br><font size=2 face="sans-serif">thanks,</font>
<br><font size=2 face="sans-serif">John</font>
<br>
<br><font size=2 face="sans-serif">## XML-RPC Service</font>
<br><font size=2 face="sans-serif">import win32serviceutil</font>
<br><font size=2 face="sans-serif">import win32service</font>
<br><font size=2 face="sans-serif">import win32event</font>
<br><font size=2 face="sans-serif">import win32evtlogutil</font>
<br><font size=2 face="sans-serif">import win32file</font>
<br><font size=2 face="sans-serif">import servicemanager</font>
<br><font size=2 face="sans-serif">import SimpleXMLRPCServer</font>
<br>
<br><font size=2 face="sans-serif">class OBJECT:</font>
<br><font size=2 face="sans-serif"> def hello(self):</font>
<br><font size=2 face="sans-serif"> return "Hello
World"</font>
<br>
<br><font size=2 face="sans-serif">class XMLRPCSERVICE(win32serviceutil.ServiceFramework):</font>
<br><font size=2 face="sans-serif"> _svc_name_ = "XMLRPCSERVICE"</font>
<br><font size=2 face="sans-serif"> _svc_display_name_ = "XMLRPCSERVICE"</font>
<br><font size=2 face="sans-serif"> _svc_description_ = "XMLRPCSERVICE"</font>
<br><font size=2 face="sans-serif"> </font>
<br><font size=2 face="sans-serif"> def __init__(self, args):</font>
<br><font size=2 face="sans-serif"> win32evtlogutil.AddSourceToRegistry(self._svc_display_name_,
sys.executable, "Application")</font>
<br><font size=2 face="sans-serif"> win32serviceutil.ServiceFramework.__init__(self,
args)</font>
<br><font size=2 face="sans-serif"> </font>
<br><font size=2 face="sans-serif"> self.hWaitStop
= win32event.CreateEvent(None, 0, 0, None)</font>
<br><font size=2 face="sans-serif"> self.hSockEvent
= win32event.CreateEvent(None, 0, 0, None)</font>
<br>
<br><font size=2 face="sans-serif"> def SvcStop(self):</font>
<br><font size=2 face="sans-serif"> self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)</font>
<br><font size=2 face="sans-serif"> win32event.SetEvent(self.hWaitStop)</font>
<br>
<br><font size=2 face="sans-serif"> def SvcDoRun(self):</font>
<br><font size=2 face="sans-serif"> ## Write
a started event</font>
<br><font size=2 face="sans-serif"> servicemanager.LogMsg(</font>
<br><font size=2 face="sans-serif">
servicemanager.EVENTLOG_INFORMATION_TYPE,</font>
<br><font size=2 face="sans-serif">
servicemanager.PYS_SERVICE_STARTED,</font>
<br><font size=2 face="sans-serif">
(self._svc_name_, ' (%s)' % self._svc_name_))</font>
<br><font size=2 face="sans-serif"> </font>
<br><font size=2 face="sans-serif"> server =
SimpleXMLRPCServer.SimpleXMLRPCServer(("", 8080))</font>
<br><font size=2 face="sans-serif"> object =
OBJECT()</font>
<br><font size=2 face="sans-serif"> server.register_instance(object)</font>
<br><font size=2 face="sans-serif"> </font>
<br><font size=2 face="sans-serif"> while 1:</font>
<br><font size=2 face="sans-serif">
win32file.WSAEventSelect(server, self.hSockEvent,win32file.FD_ACCEPT) </font>
<br><font size=2 face="sans-serif">
rc = win32event.WaitForMultipleObjects((self.hWaitStop,self.hSockEvent),
0, win32event.INFINITE)</font>
<br><font size=2 face="sans-serif">
if rc == win32event.WAIT_OBJECT_0:</font>
<br><font size=2 face="sans-serif">
break</font>
<br><font size=2 face="sans-serif">
else:</font>
<br><font size=2 face="sans-serif">
win32file.WSAEventSelect(server,self.hSockEvent, 0)</font>
<br><font size=2 face="sans-serif">
server.handle_request()</font>
<br><font size=2 face="sans-serif">
#server.serve_forever() ## Works, but breaks the Windows
service functionality</font>
<br><font size=2 face="sans-serif">
</font>
<br><font size=2 face="sans-serif"> ## Write
a stopped event</font>
<br><font size=2 face="sans-serif"> win32evtlogutil.ReportEvent(self._svc_name_,</font>
<br><font size=2 face="sans-serif">
servicemanager.PYS_SERVICE_STOPPED,0,</font>
<br><font size=2 face="sans-serif">
servicemanager.EVENTLOG_INFORMATION_TYPE,</font>
<br><font size=2 face="sans-serif">
(self._svc_name_,""))</font>
<br>
<br><font size=2 face="sans-serif">if __name__ == '__main__':</font>
<br><font size=2 face="sans-serif"> win32serviceutil.HandleCommandLine(XMLRPCSERVICE)</font>
<br>
<br><font size=2 face="sans-serif">------------------------------------------------------------------------------------------------------</font>
<br><font size=2 face="sans-serif">## XML-RPC Client</font>
<br><font size=2 face="sans-serif">import xmlrpclib</font>
<br>
<br><font size=2 face="sans-serif">server = xmlrpclib.ServerProxy("http://remoteserver:8080")</font>
<br><font size=2 face="sans-serif">print server.hello()</font>