I would like to expose a Pandas data frame with out_protocol=XmlDocument()
as a SOAP web service.
As of now, I only managed to expose a String
by calling the web service with HTTP
in_protocol. Here is the working code.
Server code:
from spyne import Application, srpc, ServiceBase, \
Integer, Unicode, String
from spyne import Iterable
from spyne.protocol.http import HttpRpc
from spyne.protocol.soap import Soap11
from spyne.protocol.json import JsonDocument
from spyne.protocol.xml import XmlDocument
from spyne.server.wsgi import WsgiApplication
class HelloWorldService(ServiceBase):
@srpc(String, Integer, _returns=String)
def say_hello(name, times):
s = ('Hi' + str(name)+' ')*times
return s
application = Application([HelloWorldService],
tns='spyne.examples.hello.http',
in_protocol=HttpRpc(), #Soap11 for SOAP client
out_protocol=XmlDocument()
)
if __name__ == '__main__':
from wsgiref.simple_server import make_server
wsgi_app = WsgiApplication(application)
server = make_server('127.0.0.1', 8000, wsgi_app)
server.serve_forever()
Client code:
curl "http://localhost:8000/say_hello?times=5&name=Dave"
How should I change the code to best expose a Pandas dataframe instead of a string. And how to make the client use the SOAP protocol to make requests?
My attempt for the SOAP Client:
from zeep import Client
client = Client('http://localhost:8000/?wsdl')
result = client.service.say_hello("Antonio", 10)
print(result)
Expected output of web service should be a table-like xml. Here is an example: