3

特定の WSDL に従って WebService を実装します。クライアントは変更できません。クライアントからのリクエストを正しく処理していますが、変数の名前空間が原因で、クライアントがレスポンスについて不平を言っています。

私が欲しいもの(WSDLに基づくsoapUI応答):

<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>

私が得ているもの(tns:検証の問題を引き起こす変数に関する通知):

<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 クライアントが次の例外をスローしています:

[com.sun.istack.SAXParseException2; 行番号: 2; columnNumber: 162; 予期しない要素 (uri:" http://callback.foo.com/ "、local:"result")。期待される要素は <{}result>,<{}notify>] です

実装スニペット:

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!")
4

3 に答える 3

1

application.interface で nsmap をオーバーライドすることで修正できます

    def fix_nsmap(application):
        conversion_dict = {
            'tns': None,
            'senv': 'soap',
        }
        nsmap = application.interface.nsmap
        for k, v in conversion_dict.iteritems():
            nsmap[v] = nsmap[k]
            del nsmap[k]

        application.interface.nsmap = nsmap

    application_security2 = Application(
        [Security2Service],
        tns=NS,
        name='Security2',
        in_protocol=Soap11(),
        out_protocol=Soap11()
    )

    fix_nsmap(application_security2)

nsmap[None] デフォルトの NS を設定します

于 2015-06-23T11:22:08.270 に答える
1

の event_manager にリスナーを追加する方法がわからない場合はmethod_return_string、以下の完全な例を参照してください。

from spyne import Application, rpc, ServiceBase, Iterable, Integer, Unicode

from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication


class HelloWorldService(ServiceBase):
    @rpc(Unicode, Integer, _returns=Iterable(Unicode))
    def say_hello(ctx, name, times):
        for i in range(times):
            yield u'Hello, %s' % name


def on_method_return_string(ctx):
    ctx.out_string[0] = ctx.out_string[0].replace(b'Hello>', b'Good by')

HelloWorldService.event_manager.add_listener('method_return_string', 
                                              on_method_return_string)

application = Application([HelloWorldService], 'spyne.examples.hello.soap',
                          in_protocol=Soap11(validator='lxml'),
                          out_protocol=Soap11())

wsgi_application = WsgiApplication(application)


if __name__ == '__main__':
    import logging

    from wsgiref.simple_server import make_server
    server = make_server('127.0.0.1', 8000, wsgi_application)
    server.serve_forever()

Spyne 2.12 の時点では、これが応答変数から名前空間を削除する唯一の方法です。

于 2016-10-13T15:58:06.073 に答える