Last active
November 9, 2015 06:51
-
-
Save oiuww09fn/332c6e83c2861064ba8d to your computer and use it in GitHub Desktop.
wsdl2py -f SquareService.wsdl && wsdl2dispatch -f SquareService.wsdl http://pywebsvcs.sourceforge.net/holger.pdf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
#!/apps/pydev/bin/python2.4 | |
# *** ZSI 2.0 *** | |
import sys | |
# Import the generated client code | |
from SquareService_services import * | |
url = "http://127.0.0.1:8080/SquareService" | |
service = SquareServiceLocator().getSquarePortType(url=url, tracefile=sys.stdout) | |
print '\nAccessing service SquareService, method getSquare...' | |
while 1: | |
try: | |
x = float(raw_input("Enter x: ")) | |
except ValueError: | |
print "X must be a number" | |
continue | |
request = getSquareRequest() | |
request._x = x | |
response = service.getSquare(request) | |
print "x**2 =", response._return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# *** ZSI 2.0 *** | |
from optparse import OptionParser | |
# Import the ZSI stuff you’d need no matter what | |
from ZSI.wstools import logging | |
from ZSI.ServiceContainer import AsServer | |
# Import the generated Server Object | |
from SquareService_services_server import SquareService | |
# Create a Server implementation by inheritance | |
class MySquareService(SquareService): | |
# Make WSDL available for HTTP GET | |
_wsdl = "".join(open("SquareService.wsdl").readlines()) | |
def soap_getSquare(self, ps, **kw): | |
# Call the generated base class method to get appropriate | |
# input/output data structures | |
response = SquareService.soap_getSquare(self, ps, **kw) | |
request = self.request | |
response._return = self.getSquare(request._x) | |
return response | |
def getSquare(self, x): | |
return x ** 2 | |
op = OptionParser(usage="%prog [options]") | |
op.add_option("-l", "--loglevel", help="loglevel (DEBUG, WARN)", | |
metavar="LOGLEVEL") | |
op.add_option("-p", "--port", help="HTTP port", | |
metavar="PORT", default=8080, type="int") | |
options, args = op.parse_args() | |
# set the loglevel according to cmd line arg | |
if options.loglevel: | |
loglevel = eval(options.loglevel, logging.__dict__) | |
logger = logging.getLogger("") | |
logger.setLevel(loglevel) | |
# Run the server with a given list services | |
AsServer(port=options.port, services=[MySquareService(), ]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<definitions name="SquareService" | |
targetNamespace="http://services.zsiserver.net:8080/SquareService" | |
xmlns:tns="http://services.zsiserver.net:8080/SquareService" | |
xmlns:xsd="http://www.w3.org/2001/XMLSchema" | |
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" | |
xmlns="http://schemas.xmlsoap.org/wsdl/"> | |
<message name="getSquareRequest"> | |
<part name="x" type="xsd:double"/> | |
</message> | |
<message name="getSquareResponse"> | |
<part name="return" type="xsd:double"/> | |
</message> | |
<portType name="SquarePortType"> | |
<operation name="getSquare"> | |
<documentation> the square method </documentation> | |
<input message="tns:getSquareRequest"/> | |
<output message="tns:getSquareResponse"/> | |
</operation> | |
</portType> | |
<binding name="SquareBinding" type="tns:SquarePortType"> | |
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> | |
<operation name="getSquare"> | |
<soap:operation soapAction="http://services.zsiserver.net:8080/SquareService/getSquare"/> | |
<input> | |
<soap:body use="literal" namespace="http://services.zsiserver.net:8080/SquareService"/> | |
</input> | |
<output> | |
<soap:body use="literal" namespace="http://services.zsiserver.net:8080/SquareService"/> | |
</output> | |
</operation> | |
</binding> | |
<service name="SquareService"> | |
<documentation>Returns x^2 (x**2, square(x)) for a given float x</documentation> | |
<port name="SquarePort" binding="tns:SquareBinding"> | |
<soap:address location="http://127.0.0.1:8080/SquareService"/> | |
</port> | |
</service> | |
</definitions> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment