I am developing with Django and Python , and I need publish 1 service with SOAP with 2 operations. For this task I chose the spyne library:
http://spyne.io/#auxproc=Sync&s=aux
Because apparently is easy to understand and start to develop. I did the first example and was fine, even I developed my own method with my internal logical. Now I need develop others features most special. My current code is:
class SopoSoap(ComplexModel):
__namespace__ = 'http://service/service.wsdl'
_type_info = {
"field1": Integer(min_occurs = 1),
"field2": Integer(min_occurs = 1),
"field3": Unicode(min_occurs = 1),
"field4": Unicode(min_occurs = 1),
"field5": Unicode(min_occurs = 0),
}
class NewIncidenceService(ServiceBase):
@rpc(SopoSoap, _returns=Integer)
def NewIncidence(sop):
# my differetns operations in code
return a.pk # integer value
application = Application([NewIncidenceService],
tns=http://service/service.wsdl',
in_protocol=Soap11(validator='lxml'),
out_protocol=Soap11(cleanup_namespaces=True)
)
createSop_app = csrf_exempt(DjangoApplication(application))
With this code everything is fine and my wsdl generated is this one:
<wsdl:definitions xmlns:wsa="http://schemas.xmlsoap.org/ws/2003/03/addressing" xmlns:tns="http://localhost/DEMAT/DEMAT_IncidenceManagement/service.wsdl" xmlns:plink="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:soap12env="http://www.w3.org/2003/05/soap-envelope/" xmlns:senc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap12enc="http://www.w3.org/2003/05/soap-encoding/" targetNamespace="http://localhost/DEMAT/DEMAT_IncidenceManagement/service.wsdl" name="Application">...</wsdl:definitions>
Now I need these changes:
First, if I try this source:
class ResponseData(ComplexModel):
message = Unicode
codResultado = Integer
class CreateIncidenceService(ServiceBase):
@rpc(SopoSoap, _returns=ResponseData)
def NewIncidence(sop):
try:
# operations
return ResponseData
I never receive answer of my server (Apache with django - wsgi.py), what I need change the rpc decorator? the type of return, where can I find a good example of documentation for dummies?
Second. This one is very important for me, I need change the name of specific elements in the wsdl, for example:
<xs:complexType name="NewIncidenceResponse">
or this others:
<wsdl:message name="NewIncidence">
<wsdl:part name="NewIncidence" element="tns:NewIncidence"/>
</wsdl:message>
<wsdl:message name="NewIncidenceResponse">
<wsdl:part name="NewIncidenceResponse" element="tns:NewIncidenceResponse"/>
</wsdl:message>
The name, only the name, I suppose this should be so simple, because in Java or .net you can change the name of these parameters without problems, but with this library I don't know how can I do it?
Three, I would like return a complexType with a structure with 3 fields:
a) code b) message c) Exception: Here I don't know how can I return the exception to the wsdl.
For these 3 fields I thought in the responseData class created by me, but I can`t get return this type of data. I know I am asking 3 questions but I was reading all the documentation of spyne and I didn't find anything for my problems.
First, thanks for trying Spyne out!
Answers:
Try
return ResponseData(codResultado=1234, message="Hello!")
Pass _out_response_name
to @rpc
Don't invent yours and use the built-in Fault
class.
Spyne docs are bad, yes, but they aren't THAT bad. Read them :)
Spyne also has a mailing list: http://lists.spyne.io/listinfo/people
Hth,