473,624 Members | 2,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Windows XMLRPC Service

Hi,

I'm trying to serve up a simple XMLRPC server as a windows service. I
got it to run properly, I'm just not sure how to stop it properly.
Most of the documentation/examples I found for this was from forums,
so I'd love some links to relevant info also. Here's what I
have...taken from the cookbook with the xmlrpc server added:

import win32serviceuti l
import win32service
import win32event

import SimpleXMLRPCSer ver

class MyClass(object) :
def hello(self):
return "Hello World!"

class SmallestPythonS ervice(win32ser viceutil.Servic eFramework):
_svc_name_ = "PythonXMLR PC"
_svc_display_na me_ = "PythonXMLR PC"

def __init__(self, args):
win32serviceuti l.ServiceFramew ork.__init__(se lf, args)
# Create an event which we will use to wait on.
# The "service stop" request will set this event.
self.hWaitStop = win32event.Crea teEvent(None, 0, 0, None)

def SvcStop(self):
# Before we do anything, tell the SCM we are starting the stop
process.
self.ReportServ iceStatus(win32 service.SERVICE _STOP_PENDING)

# quit the xmlrpc sever
self.server.qui t()

# And set my event.
win32event.SetE vent(self.hWait Stop)

def SvcDoRun(self):
# Serve up the XMLRPC forever
self.server =
SimpleXMLRPCSer ver.SimpleXMLRP CServer(("10.0. 1.6", 8000))
self.server.reg ister_instance( MyClass())
self.server.ser ve_forever()

win32event.Wait ForSingleObject (self.hWaitStop )
if __name__=='__ma in__':
win32serviceuti l.HandleCommand Line(SmallestPy thonService)

~Sean

Jun 18 '07 #1
6 2490
En Mon, 18 Jun 2007 00:25:25 -0300, <ha**********@g mail.comescribi ó:
I'm trying to serve up a simple XMLRPC server as a windows service. I
got it to run properly, I'm just not sure how to stop it properly.
Most of the documentation/examples I found for this was from forums,
so I'd love some links to relevant info also. Here's what I
have...taken from the cookbook with the xmlrpc server added:

def __init__(self, args):
win32serviceuti l.ServiceFramew ork.__init__(se lf, args)
# Create an event which we will use to wait on.
# The "service stop" request will set this event.
self.hWaitStop = win32event.Crea teEvent(None, 0, 0, None)

def SvcStop(self):
# Before we do anything, tell the SCM we are starting the stop
process.
self.ReportServ iceStatus(win32 service.SERVICE _STOP_PENDING)

# quit the xmlrpc sever
self.server.qui t()
What is quit()? As the server may be processing a request I'd move any
finalization code below, after exiting the while loop.
>
# And set my event.
win32event.SetE vent(self.hWait Stop)

def SvcDoRun(self):
# Serve up the XMLRPC forever
self.server =
SimpleXMLRPCSer ver.SimpleXMLRP CServer(("10.0. 1.6", 8000))
self.server.reg ister_instance( MyClass())
self.server.ser ve_forever()

win32event.Wait ForSingleObject (self.hWaitStop )
The simplest solution is to replace serve_forever with a loop waiting on
hWaitStop:

while WaitForSingleOb ject(self.hWait Stop, 0)==WAIT_TIMEOU T:
self.server.han dle_request()

Set the socket timeout to a reasonable value (you'll have to wait that
time before exiting). Also, a ThreadingTCPSer ver may be better if you
expect more than a request at a time. If you search past messages you may
find other ways.

--
Gabriel Genellina

Jun 18 '07 #2
On Jun 18, 2:16 am, "Gabriel Genellina" <gagsl-...@yahoo.com.a r>
wrote:
En Mon, 18 Jun 2007 00:25:25 -0300, <half.ital...@g mail.comescribi ó:


I'm trying to serve up a simple XMLRPC server as a windows service. I
got it to run properly, I'm just not sure how to stop it properly.
Most of the documentation/examples I found for this was from forums,
so I'd love some links to relevant info also. Here's what I
have...taken from the cookbook with the xmlrpc server added:
def __init__(self, args):
win32serviceuti l.ServiceFramew ork.__init__(se lf, args)
# Create an event which we will use to wait on.
# The "service stop" request will set this event.
self.hWaitStop = win32event.Crea teEvent(None, 0, 0, None)
def SvcStop(self):
# Before we do anything, tell the SCM we are starting the stop
process.
self.ReportServ iceStatus(win32 service.SERVICE _STOP_PENDING)
# quit the xmlrpc sever
self.server.qui t()

What is quit()? As the server may be processing a request I'd move any
finalization code below, after exiting the while loop.
# And set my event.
win32event.SetE vent(self.hWait Stop)
def SvcDoRun(self):
# Serve up the XMLRPC forever
self.server =
SimpleXMLRPCSer ver.SimpleXMLRP CServer(("10.0. 1.6", 8000))
self.server.reg ister_instance( MyClass())
self.server.ser ve_forever()
win32event.Wait ForSingleObject (self.hWaitStop )

The simplest solution is to replace serve_forever with a loop waiting on
hWaitStop:

while WaitForSingleOb ject(self.hWait Stop, 0)==WAIT_TIMEOU T:
self.server.han dle_request()

Set the socket timeout to a reasonable value (you'll have to wait that
time before exiting). Also, a ThreadingTCPSer ver may be better if you
expect more than a request at a time. If you search past messages you may
find other ways.

--
Gabriel Genellina- Hide quoted text -

- Show quoted text -
I can't quite figure out where to set the "socket timeout". I tried
setting win32event.WAIT _TIMEOUT, but I'm pretty sure that's not the
variable you were talking about. I did manage to make it multi-
threaded by incorporating a different recipe, and I'm beginning to
understand the control flow a bit better, but it doesn't seem to be
doing what I expect. When SvcStop() is executed and calls
win32event.SetE vent(self.hWait Stop), the while loop should break as
win32event.Wait ForSingleObject (self.hWaitStop , 0) returns zero at this
point. But it doesn't do that. What am I missing?

import win32serviceuti l
import win32service
import win32event

import SocketServer
from SimpleXMLRPCSer ver import
SimpleXMLRPCSer ver,SimpleXMLRP CRequestHandler

# Threaded mix-in
class
AsyncXMLRPCServ er(SocketServer .ThreadingMixIn ,SimpleXMLRPCSe rver):
pass
class MyClass(object) :
def hello(self):
return "Hello World"

class SmallestPythonS ervice(win32ser viceutil.Servic eFramework):
_svc_name_ = "PythonXMLR PC"
_svc_display_na me_ = "PythonXMLR PC"

def __init__(self, args):
win32serviceuti l.ServiceFramew ork.__init__(se lf, args)
# Create an event which we will use to wait on.
self.hWaitStop = win32event.Crea teEvent(None, 0, 0, None)
import socket
localhost = socket.gethostb yname(socket.ge thostname())
self.server = AsyncXMLRPCServ er((localhost, 8000),
SimpleXMLRPCReq uestHandler)

def SvcStop(self):
self.ReportServ iceStatus(win32 service.SERVICE _STOP_PENDING)
win32event.SetE vent(self.hWait Stop)
#print "EVENT:",
win32event.Wait ForSingleObject (self.hWaitStop , 0) # returns 0 here

def SvcDoRun(self):
self.server.reg ister_instance( MyClass())

#win32event.WAI T_TIMEOUT = 2 --- This just makes the loop
never execute because
# the WaitFor... part always returns 258

while win32event.Wait ForSingleObject (self.hWaitStop , 0) ==
win32event.WAIT _TIMEOUT:
self.server.han dle_request()

if __name__ == '__main__':
win32serviceuti l.HandleCommand Line(SmallestPy thonService)

Thanks for any help!

~Sean

Jun 19 '07 #3
En Tue, 19 Jun 2007 03:45:19 -0300, <ha**********@g mail.comescribi ó:

I can't quite figure out where to set the "socket timeout". I tried
setting win32event.WAIT _TIMEOUT, but I'm pretty sure that's not the
variable you were talking about. I did manage to make it multi-
threaded by incorporating a different recipe, and I'm beginning to
understand the control flow a bit better, but it doesn't seem to be
doing what I expect. When SvcStop() is executed and calls
win32event.SetE vent(self.hWait Stop), the while loop should break as
win32event.Wait ForSingleObject (self.hWaitStop , 0) returns zero at this
point. But it doesn't do that. What am I missing?
May be because you didn't set correctly the socket timeout. See the
comments below.
>
def SvcStop(self):
self.ReportServ iceStatus(win32 service.SERVICE _STOP_PENDING)
win32event.SetE vent(self.hWait Stop)
#print "EVENT:",
win32event.Wait ForSingleObject (self.hWaitStop , 0) # returns 0 here
That's OK, since you have set the event.
def SvcDoRun(self):
self.server.reg ister_instance( MyClass())

#win32event.WAI T_TIMEOUT = 2 --- This just makes the loop
never execute because
# the WaitFor... part always returns 258
WAIT_TIMEOUT is 258. How do you see it is 2?
For example, see <http://msdn2.microsoft .com/en-us/library/ms681382.aspx>.
Python 2.5.1 + pywin32 210 prints this on my PC:
pyimport win32event
pywin32event.WA IT_TIMEOUT
258
while win32event.Wait ForSingleObject (self.hWaitStop , 0) ==
win32event.WAIT _TIMEOUT:
self.server.han dle_request()
The loop above should keep running until hWaitStop is set, with a maximum
wait time (inside handle_request) corresponding to the socket timeout
value.
You can either:
- use socket.setdefau lttimeout() (in __init__, by example) before anything
else. This will set a global timeout for all sockets.
- modify the socket instance. Just add this method to your AsyncServer:
def server_activate (self):
SimpleXMLRPCSer ver.server_acti vate(self)
self.socket.set timeout(15) # for 15 secs
--
Gabriel Genellina

Jun 19 '07 #4
On Jun 19, 10:21 am, "Gabriel Genellina" <gagsl-...@yahoo.com.a r>
wrote:
En Tue, 19 Jun 2007 03:45:19 -0300, <half.ital...@g mail.comescribi ó:
I can't quite figure out where to set the "socket timeout". I tried
setting win32event.WAIT _TIMEOUT, but I'm pretty sure that's not the
variable you were talking about. I did manage to make it multi-
threaded by incorporating a different recipe, and I'm beginning to
understand the control flow a bit better, but it doesn't seem to be
doing what I expect. When SvcStop() is executed and calls
win32event.SetE vent(self.hWait Stop), the while loop should break as
win32event.Wait ForSingleObject (self.hWaitStop , 0) returns zero at this
point. But it doesn't do that. What am I missing?

May be because you didn't set correctly the socket timeout. See the
comments below.
def SvcStop(self):
self.ReportServ iceStatus(win32 service.SERVICE _STOP_PENDING)
win32event.SetE vent(self.hWait Stop)
#print "EVENT:",
win32event.Wait ForSingleObject (self.hWaitStop , 0) # returns 0 here

That's OK, since you have set the event.
def SvcDoRun(self):
self.server.reg ister_instance( MyClass())
#win32event.WAI T_TIMEOUT = 2 --- This just makes the loop
never execute because
# the WaitFor... part always returns 258

WAIT_TIMEOUT is 258. How do you see it is 2?
For example, see <http://msdn2.microsoft .com/en-us/library/ms681382.aspx>.
Python 2.5.1 + pywin32 210 prints this on my PC:
pyimport win32event
pywin32event.WA IT_TIMEOUT
258
while win32event.Wait ForSingleObject (self.hWaitStop , 0) ==
win32event.WAIT _TIMEOUT:
self.server.han dle_request()

The loop above should keep running until hWaitStop is set, with a maximum
wait time (inside handle_request) corresponding to the socket timeout
value.
You can either:
- use socket.setdefau lttimeout() (in __init__, by example) before anything
else. This will set a global timeout for all sockets.
- modify the socket instance. Just add this method to your AsyncServer:
def server_activate (self):
SimpleXMLRPCSer ver.server_acti vate(self)
self.socket.set timeout(15) # for 15 secs

--
Gabriel Genellina
def SvcDoRun(self):
self.server.reg ister_instance( MyClass())
#win32event.WAI T_TIMEOUT = 2 --- This just makes the loop
never execute because
# the WaitFor... part always returns 258

WAIT_TIMEOUT is 258. How do you see it is 2?
For example, see <http://msdn2.microsoft .com/en-us/library/ms681382.aspx>.
Python 2.5.1 + pywin32 210 prints this on my PC:
pyimport win32event
pywin32event.WA IT_TIMEOUT
258
I meant here that *if* I set the WAIT_TIMEOUT to 2, then I see that
behavior.
- use socket.setdefau lttimeout() (in __init__, by example) before anything
else. This will set a global timeout for all sockets.
That was the one that did it.

Thank you again Gabriel. I'll post back with something complete.

~Sean

Jun 19 '07 #5
En Tue, 19 Jun 2007 14:57:10 -0300, <ha**********@g mail.comescribi ó:
#win32event.WAI T_TIMEOUT = 2 --- This just makes the loop
never execute because
# the WaitFor... part always returns 258

WAIT_TIMEOUT is 258. How do you see it is 2?
pyimport win32event
pywin32event.W AIT_TIMEOUT
258

I meant here that *if* I set the WAIT_TIMEOUT to 2, then I see that
behavior.
Ah, ok! I should have stated clearly that WAIT_TIMEOUT is a Windows
predefined constant, not your desired timeout value.
Thank you again Gabriel. I'll post back with something complete.
Yes, please, a working example would be nice for future readers...

--
Gabriel Genellina

Jun 19 '07 #6
On Jun 19, 12:32 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.a r>
wrote:
En Tue, 19 Jun 2007 14:57:10 -0300, <half.ital...@g mail.comescribi ó:
#win32event.WAI T_TIMEOUT = 2 --- This just makes the loop
never execute because
# the WaitFor... part always returns 258
WAIT_TIMEOUT is 258. How do you see it is 2?
pyimport win32event
pywin32event.WA IT_TIMEOUT
258
I meant here that *if* I set the WAIT_TIMEOUT to 2, then I see that
behavior.

Ah, ok! I should have stated clearly that WAIT_TIMEOUT is a Windows
predefined constant, not your desired timeout value.
Thank you again Gabriel. I'll post back with something complete.

Yes, please, a working example would be nice for future readers...

--
Gabriel Genellina
For posterity...

import sys
import win32serviceuti l
import win32service
import win32event
import win32evtlogutil
import servicemanager

import SocketServer, socket
from SimpleXMLRPCSer ver import
SimpleXMLRPCSer ver,SimpleXMLRP CRequestHandler

# Threaded mix-in
class
AsyncXMLRPCServ er(SocketServer .ThreadingMixIn ,SimpleXMLRPCSe rver):
pass

import XMLRPC_funcs # module containing the functions wrapped in a
class

class XMLRPCservice(w in32serviceutil .ServiceFramewo rk):
_svc_name_ = "PythonXMLR PC"
_svc_display_na me_ = "PythonXMLR PC"
_svc_descriptio n_ = "Multi-threaded Python XMLRPC Server"

def __init__(self, args):
# set the timeout so the service can stop...Otherwis e it hangs
forever
socket.setdefau lttimeout(15)

win32evtlogutil .AddSourceToReg istry(self._svc _display_name_,
sys.executable, "Applicatio n")
win32serviceuti l.ServiceFramew ork.__init__(se lf, args)

# Create an event which we will use to wait on.
self.hWaitStop = win32event.Crea teEvent(None, 0, 0, None)
localhost = socket.gethostb yname(socket.ge thostname())
self.server = AsyncXMLRPCServ er((localhost, 8000),
SimpleXMLRPCReq uestHandler)

def SvcStop(self):
self.ReportServ iceStatus(win32 service.SERVICE _STOP_PENDING)
#send the stop event
win32event.SetE vent(self.hWait Stop)

def SvcDoRun(self):
# log a start msg

servicemanager. LogMsg(servicem anager.EVENTLOG _INFORMATION_TY PE,
servicemanager. PYS_SERVICE_STA RTED,
(self._svc_name _, ' (%s)' %
self._svc_name_ ))

self.server.reg ister_instance( XMLRPC_funcs.XM LRPC_funcs())

# handle requests until the stop event is received
while win32event.Wait ForSingleObject (self.hWaitStop , 0) ==
win32event.WAIT _TIMEOUT:
self.server.han dle_request()

# log a stopped msg
win32evtlogutil .ReportEvent(se lf._svc_name_,
servicemanager. PYS_SERVICE_STO PPED,
0,

servicemanager. EVENTLOG_INFORM ATION_TYPE,
(self._svc_name _,""))

if __name__ == '__main__':
win32serviceuti l.HandleCommand Line(XMLRPCserv ice)

Jun 20 '07 #7

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

Similar topics

0
1830
by: glin | last post by:
Hi I am trying to integrate the xmlrpc server into a class, does anyone know how to get it working? test.html: <html> <head> <title>XMLRPC Test</title> <script src="jsolait/init.js"></script> <script src="jsolait/lib/urllib.js"></script> <script src="jsolait/lib/xml.js"></script>
0
1728
by: Juan Carlos CORUÑA | last post by:
Hello all, I'm trying to create a COM Server with an embedded xmlrpc server. Here is way it must work: - The client application (programmed with a COM capable language) instantiates my COM server (programmed with python). - The COM server must have a connect interface in order to let the client application process the xmlrpc request. - After executing a "serveforever" method on the COM server it begins
12
2238
by: dcrespo | last post by:
Hi to all... Someone knows if is there possible to have a Python SOAP or XMLRPC server that works with VB? I would like you to include the examples clients and server programs. My examples are: #Server.py import SOAPpy
0
1993
by: JDF | last post by:
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...
0
1194
by: Laszlo Nagy | last post by:
I'm running a service on a machine. The service is written in Python (of course) and it connects to an XMLRPC server periodically. It recreates the ServerProxy instance each time it needs to connect to the RPC server. The server is created with this code: server = xmlrpclib.ServerProxy(local.SERVER_URL,allow_none=True) # local.SERVER_URL is something like 'https://myserver.com:3421'
0
1411
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 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...
0
2745
by: Benjamin Grieshaber | last post by:
Hi, I´m on SuSE 9.3 with xmlrpc-c and xmlrpc-c-devel installed (ver. 0.9.10) I tried to compile php with xmlrpc support and got the following errors: ext/xmlrpc/.libs/xmlrpc-epi-php.o(.text+0x359): In function `set_zval_xmlrpc_type': /php-5.2.5/ext/xmlrpc/xmlrpc-epi-php.c:1313: undefined reference to `XMLRPC_CreateValueDateTime_ISO8601'
2
1866
by: Guilherme Polo | last post by:
On 10/29/08, Zix <saviourms@yahoo.co.inwrote: Why did you decide to "expose" a web service through xmlrpc instead of actually exposing it by using a restful web service ? The links pointed by the previous email should help you, but well, I'm still surprised on this decision specially because you said you read a lot about this topic.
0
2777
by: sarabonn | last post by:
Hello everyone, Till now i was using web services. I have to use xmlrpc in c# to request for a service. my server api object look likes this .. chawpref(id, {'aw_report':{'evt_move':False, 'evt_change':True,}} The api url is http://www.blabla.com/api/ap_chawpref.html like this. My doubt is how can send xmlrpc request from c#.Net to this url. Actually i had look at the cookcomputing xmlrpc dll but i have no clue how can use...
0
8242
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8681
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8629
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7170
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4084
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.