Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
604 views
in Technique[技术] by (71.8m points)

python - Remove the namespace from Spyne response variables

Implementing a WebService according to a specific WSDL. Client cannot be changed. Correctly processing request from Client, but Client is complaining on Response because of namespace in variables.

What I want (soapUI response based on WSDL):

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cal="http://callback.foo.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <cal:foo_statusResponse>
         <result>SUCCESS</result>
         <notify>Thanks!</notify>
      </cal:foo_statusResponse>
   </soapenv:Body>
</soapenv:Envelope>

What I am getting (notice tns: on variables causing validation issues):

<senv:Envelope xmlns:tns="http://callback.foo.com/" xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/">
  <senv:Body>
    <tns:foo_statusResponse>
      <tns:result>SUCCESS</tns:result>
      <tns:notify>Thanks!</tns:notify>
    </tns:foo_statusResponse>
  </senv:Body>
</senv:Envelope>

Java Client is throwing this exception:

[com.sun.istack.SAXParseException2; lineNumber: 2; columnNumber: 162; unexpected element (uri:"http://callback.foo.com/", local:"result"). Expected elements are <{}result>,<{}notify>]

Implementation snippet:

class fooStatusRS(ComplexModel):
    result = Unicode()
    notify = Unicode()

class foo_callback(ServiceBase):
    @srpc(Unicode, Unicode, Unicode, Unicode, statusbarInfo, anotherResponse, 
            _out_header=None, 
            _out_variable_names=("result", "notify"), 
            _returns=(Unicode, Unicode), 
            _out_message_name="foo_statusResponse",
            _operation_name="foo_status_rq")
    def foo_status(foo_id, reply, ref, status, statusbar, another):
        if foo_id:
            print foo_id

        return fooStatusRS(result="SUCCESS", notify="Foo received!")
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is not possible (yet) and is answered in a similar question here by the maintainer.

The work around was to add listener to the event_manager for "method_return_string" and then perform some string operations.

def _method_return_string(ctx):
    ctx.out_string[0] = ctx.out_string[0].replace("tns:result>", "result>")
    ctx.out_string[0] = ctx.out_string[0].replace("tns:notify>", "notify>")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...