Replies: 10 comments 1 reply
-
please move this to discussions so i can answer you. |
Beta Was this translation helpful? Give feedback.
-
Hello, Your return type is QueryExpressionType, but you're returning an xml document. Please find the corrected version: from lxml import etree
from spyne import Application, rpc, ServiceBase
from spyne.protocol.soap import Soap11
from spyne.model.primitive import AnyXml
from spyne.model.complex import ComplexModel
from spyne.server.wsgi import WsgiApplication
class QueryExpressionType(ComplexModel):
p = AnyXml
class TestCls(ServiceBase):
@rpc(AnyXml,
_returns=QueryExpressionType
)
def testMtd(ctx, p):
logging.debug("Received: %s", etree.tostring(p, pretty_print=True))
return QueryExpressionType(p=p)
application = Application([TestCls], 'test.ns',
in_protocol=Soap11(validator='lxml'),
out_protocol=Soap11())
wsgi_application = WsgiApplication(application)
if __name__ == '__main__':
import logging
from wsgiref.simple_server import make_server
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
logging.info("listening to http://127.0.0.1:8000")
logging.info("wsdl is at: http://localhost:8000/?wsdl")
server = make_server('127.0.0.1', 8000, wsgi_application)
server.serve_forever() Request curl -s http://localhost:8000 --data-binary @- <<EOF | tidy -xml -indent -wrap 0 -quiet
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<testMtd xmlns="test.ns">
<p>
<!-- Any elements -->
<q>test</q>
</p>
</testMtd>
</Body>
</Envelope>
EOF Response: <?xml version='1.0' encoding='utf-8'?>
<soap11env:Envelope xmlns:soap11env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="test.ns">
<soap11env:Body>
<tns:testMtdResponse>
<tns:testMtdResult>
<tns:p>
<tns:q>test</tns:q>
</tns:p>
</tns:testMtdResult>
</tns:testMtdResponse>
</soap11env:Body>
</soap11env:Envelope> |
Beta Was this translation helpful? Give feedback.
-
Thank you. Your option works. With the return of a value, everything is clear. But I need not AnyXml to be passed to the input, but QueryExpressionType, since it is actually more complicated than in my example. Is it possible to pass to the input a complex type, one of which is Any? Example:
|
Beta Was this translation helpful? Give feedback.
-
Here's something that sounds like what you need: class QueryExpressionType(ComplexModel):
any = AnyXml
class TestCls(ServiceBase):
@rpc(QueryExpressionType,
_returns=QueryExpressionType
)
def testMtd(ctx, p):
logging.debug("Received: %s", etree.tostring(p.any, pretty_print=True))
return p It should work with the following doc <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<testMtd xmlns="test.ns">
<p>
<any>
<!-- Any elements -->
<q>test</q>
</any>
</p>
</testMtd>
</Body>
</Envelope> |
Beta Was this translation helpful? Give feedback.
-
My code:
Query:
I get an error:
|
Beta Was this translation helpful? Give feedback.
-
As you now have a working example, you should go from my example to yours in baby steps. When your code stops working, that's your mistake right there. |
Beta Was this translation helpful? Give feedback.
-
Thank you, I need to be careful. But how then to describe the class QueryExpressionType so that Spyne returns a schema
but the request did not require the Any tag? |
Beta Was this translation helpful? Give feedback.
-
I'm asking this because I don't have the code handy. What is the current schema you have? What's wrong with it? |
Beta Was this translation helpful? Give feedback.
-
I'll try to explain it with another example. xsd:
My code:
On request:
printed: On request:
printed: How do I configure Spyne so that the request does not require the Any tag? |
Beta Was this translation helpful? Give feedback.
-
Hello,
The following models your document in spyne notation: class Person(ComplexModel):
_type_info = [
('firstname', Unicode),
('lastname', Unicode),
('children', Array(Unicode(sub_name="childname"))),
]
class TestCls(ServiceBase):
@rpc(Person, _returns=Person)
def testMtd(ctx, person):
logging.debug("Received: %r", person)
return person Here, you need to use Anyway, here's a way to test: $ curl -s http://localhost:8000 --data-binary @- <<EOF | tidy -xml -indent -wrap 0 -quiet
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<testMtd xmlns="test.ns">
<person>
<firstname>Hege</firstname>
<lastname>Refsnes</lastname>
<children>
<childname>Cecilie</childname>
</children>
</person>
</testMtd>
</Body>
</Envelope>
EOF Response: <?xml version='1.0' encoding='utf-8'?>
<soap11env:Envelope xmlns:soap11env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="test.ns">
<soap11env:Body>
<tns:testMtdResponse>
<tns:testMtdResult>
<tns:firstname>Hege</tns:firstname>
<tns:lastname>Refsnes</tns:lastname>
<tns:children>
<tns:childname>Cecilie</tns:childname>
</tns:children>
</tns:testMtdResult>
</tns:testMtdResponse>
</soap11env:Body>
</soap11env:Envelope> I hope that helps |
Beta Was this translation helpful? Give feedback.
-
I need the service to accept data according to the xsd:
My code:
My request:
Service response:
Why am I getting this?
How do I get the answer:
Beta Was this translation helpful? Give feedback.
All reactions