ZopeMag's mascot the ZOPE fish

Listing 4a - First part of the Webservice

1.	import sys, StringIO

2.	  # import modules for Web service
3.	  from ZSI import TC
4.	  from ZSI import *


5.	  def showPlayerAverage(self, REQUEST):
6.	      """ parses a SOAP request with PlayerName and Scores, wich 
7.	      is send to the method in the variable 'soap_data' in 
8.	      the REQUEST, and sends back a SOAP response with the average 
9.	      of the scores """

10.	if REQUEST.has_key('soap_data'):
11.	    IN_VAR = REQUEST.get('soap_data')
12.	else:
13.	    raise "Error", "No Input"

14.	OUT = StringIO.StringIO()

15.	try:
16.	    ps = ParsedSoap(IN_VAR)
17.	except ParseException, e:
18.	    FaultFromZSIException(e).AsSOAP(OUT) 
19.	    REQUEST.RESPONSE.setBody(OUT.getvalue())
20.	    REQUEST.RESPONSE.setHeader('Content-Type', 'text/xml', 0)
21.	    return REQUEST.RESPONSE
22.	except Exception, e:
23.	    # Faulted while processing; assume it's in the header.
24.	    FaultFromException(e, 1).AsSOAP(OUT) 
25.	    REQUEST.RESPONSE.setBody(OUT.getvalue())
26.	    REQUEST.RESPONSE.setHeader('Content-Type', 'text/xml', 0)
27.	    return REQUEST.RESPONSE

28.	# We are not prepared to handle any actors or 
29.	# mustUnderstand elements.
30.	# Arbitrary fault back with the first one found.
31.	a = ps.WhatActorsArePresent()
32.	if len(a):
33.	    FaultFromActor(a[0]).AsSOAP(OUT) 
34.	    REQUEST.RESPONSE.setBody(OUT.getvalue())
35.	    REQUEST.RESPONSE.setHeader('Content-Type', 'text/xml', 0)
36.	    return REQUEST.RESPONSE
37.	mu = ps.WhatMustIUnderstand()
38.	if len(mu):
39.	    uri, localname = mu[0]
40.	    FaultFromNotUnderstood(uri, localname).AsSOAP(OUT) 
41.	    REQUEST.RESPONSE.setBody(OUT.getvalue())
42.	    REQUEST.RESPONSE.setHeader('Content-Type', 'text/xml', 0)
43.	    return REQUEST.RESPONSE



Home   Subscribe   FAQ   Contact   Write for us   Privacy Policy   Weekly News   PyZine   opensourcexperts.com  

Reproduction of material from any of ZopeMag's pages without prior written permission is strictly prohibited. Copyright 2003 - 2005 ZopeMag Zope/Plone hosting by Nidelven IT