Gentlefolk,
I have been tasked with replacing an existing set of SOAP services and I have
been experimenting with the using soaplib-2.0.0 beta 2 to do so via a wgsi
handler talking to a Mongrel2 webserver. My handler is using the m2wsgi
python library programatically and is retrieving data from MongoDB instance
via pymongo. Not too shabby for someone without any real experience with
python or SOAP :)
I have been using soapUI to do my testing which all works as expected,
except I am getting odd namespace prefixes in the responses generated by
soaplib.
I think I have set the namespace for my services correctly in my use of the
soaplib.core.Application function as follows:
soapapplication = soaplib.core.Application([ClientService], 'eas')
The guts of a request looks like this:
<eas:RequestLetterStatus>
<eas:Account>TESTACC</eas:Account>
<eas:LetterReference>12345</eas:LetterReference>
</eas:RequestLetterStatus>
The response I get includes:
<tns:RequestLetterStatusResponse>
<tns:RequestLetterStatusResult>
<s1:LetterStatus>
<s1:Status>Unknown</s1:Status>
</s1:LetterStatus>
</tns:RequestLetterStatusResult>
</tns:RequestLetterStatusResponse>
Are the tns & s1 namespaces shwoing in the response correct ?
I expected to see the eas namespace I had specified in the call to
soaplib.core.Application().
I have attahced the script I am using.
-- Dave
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# ripped off from soaplib 2.0.0 beta 1 examples and modified to use m2wsgi
#
# N.B. soap appears to be interchangeable with rpc because of rpclib fork
#
import soaplib
from soaplib.core.service import soap, DefinitionBase
from soaplib.core.model.primitive import String, Integer
from soaplib.core.server import wsgi
from soaplib.core.model.clazz import ClassModel, Array
import pymongo
from pymongo import Connection
import string
class LetterStatus(ClassModel):
__namespace__ = "letterstatus"
Reference = String
ServiceNumber = String
LetterIndex = String
LetterId = String
WhenCreated = String
WhenLodged = String
Status = String
class ClientService(DefinitionBase):
@soap(String, Integer, _returns=Array(String))
def say_hello(self,name,times):
results = []
for i in range(0, times):
results.append('Hello, %s' % name)
return results
@soap(String, Array(String), _returns=Array(LetterStatus))
def RequestLetterStatus(self, Account, LetterReferences):
results = {}
for i in range(0, len(LetterReferences)):
letterstatus = LetterStatus()
letter = db.letters.find_one({ "account" : Account, "reference" : LetterReferences[i] }, { "id" : 1, "reference" : 1, "dbid" : 1 } )
if letter == None:
letterstatus.Reference = LetterReferences[i]
letterstatus.ServiceNumber = ''
letterstatus.LetterIndex = ''
letterstatus.LetterId = ''
letterstatus.WhenCreated = ''
letterstatus.WhenLodged = ''
letterstatus.Status = 'Unknown'
else:
letter_id = string.split(letter.get('id', ''), ':')
letterstatus.Reference = letter.get('reference', '')
letterstatus.ServiceNumber = letter_id[0]
letterstatus.LetterIndex = str(int(letter_id[1]) + 1)
letterstatus.LetterId = str(letter.get('dbid', ''))
pack = db.packs.find_one({ "id" : letter_id[0] }, { "id" : 1, "reference" : 1, "dbid" : 1, "received" : 1, "processed" : 1, "status" : 1 })
if pack == None:
letterstatus.WhenCreated = ''
letterstatus.WhenLodged = ''
letterstatus.Status = 'Unknown'
else:
letterstatus.WhenCreated = str(pack.get('received', ''))
letterstatus.WhenLodged = 'Not set yet'
letterstatus.Status = pack.get('status', 'Not set yet')
results[i] = letterstatus
return [v for k, v in results.items()]
if __name__=='__main__':
try:
from m2wsgi.io.standard import WSGIHandler
db = Connection().testdb
soap_application = soaplib.core.Application([ClientService], 'eas')
wsgi_application = wsgi.Application(soap_application)
handler = WSGIHandler(wsgi_application, "tcp://127.0.0.1:9991")
handler.serve()
except ImportError:
print "Error: example server code requires Python >= 2.5"
_______________________________________________
Soap mailing list
[email protected]
http://mail.python.org/mailman/listinfo/soap