为了账号安全,请及时绑定邮箱和手机立即绑定

有没有办法用 c++ Gsoap 客户端调用 python soap spyne 服务器?

有没有办法用 c++ Gsoap 客户端调用 python soap spyne 服务器?

慕村225694 2022-04-27 16:27:39
实际上我有一个使用soap spyne运行的python脚本和soap服务器,我需要使用c ++ gsoap客户端调用该soap api,以便python脚本将运行并获取输出作为对客户端的响应,我可以使用SOAP调用api UI和python zeep客户端但是当我尝试使用gsoap调用客户端时它给了我错误DEBUG:spyne.protocol.soap.soap11:ValueError: lxml 不支持从带有编码声明的 unicode 字符串反序列化gsoap 和soap spyne 生成的wsdl 文件也有不同的命名空间```pythonfrom spyne import Application, rpc, ServiceBase, Integer,     Unicode,Stringfrom spyne.protocol.soap import Soap11from spyne.server.wsgi import WsgiApplicationfrom spyne.model.complex import ComplexModelfrom spyne.model.complex import Arrayfrom twisted.internet import reactorfrom twisted.web.server import Sitefrom twisted.web.wsgi import WSGIResourcefrom twisted.python import logimport syssys.path.insert(1,'../cloud-client/slicing')import speech as tclass caps__CSoapReqBuf(ComplexModel):    stringarray=String    size=Integerclass caps__CSoapResponse(ComplexModel):    __namespace__ = "spyne.examples.hello.soap"    nRetCode=Integer    strResponseData=Stringclass caps__CSoapRequest(ComplexModel):    __namespace__ = "spyne.examples.hello.soap"    nRequestType = Integer    wstrRequestParam= Stringclass caps_CCallbackData(ComplexModel):    __namespace__ = "spyne.examples.hello.soap"    nPort=Integer    strFunction = Stringclass TranscriptionService(ServiceBase):    @rpc(String, String, caps_CCallbackData, caps__CSoapResponse,     _returns=Integer)    def caps__SoapRequestString(ctx, function_name, SoapRequest,     CallbackData, SoapResponse):        parameters = SoapRequest        list = parameters.split('|')        d = dict(s.split(':') for s in list)        filename = d['path']        samplerate = int(d['sr'])        outputpath = d['outputpath']
查看完整描述

2 回答

?
开心每一天1111

TA贡献1836条经验 获得超13个赞

我对此的解决方案是让 lxml 失败并使用 WebOb 手动解析有效负载,然后将其放置在用户定义的上下文中。您可以稍后访问ctx.udc以访问数据。所以:


...

from webob import Request as WebObRequest

...


HOST = '0.0.0.0'

PORT = 8000


# parse payload manually 

def _on_wsgi_call(ctx):

    req = WebObRequest(ctx.transport.req)

    decoded = req.body.decode('utf-8')

    envelope = Etree.fromstring(decoded)


    # depending on your data, you may need to update this step 

    element = next(envelope.iter())

    ctx.udc = element.text



if __name__ == '__main__':

    application = initialize([YourService])

    wsgi_application = WsgiApplication(application)

    wsgi_application.event_manager.add_listener('wsgi_call', _on_wsgi_call)

    resource = WSGIResource(reactor, reactor, wsgi_application)

    site = Site(resource)

    reactor.listenTCP(PORT, site, interface=HOST)


    logging.info('listening on: %s:%d' % (HOST, PORT))

    logging.info('wsdl is at: http://%s:%d/?wsdl' % (HOST, PORT))


    sys.exit(reactor.run())


查看完整回答
反对 回复 2022-04-27
?
波斯汪

TA贡献1811条经验 获得超4个赞

在这方面,lxml 对它认为可以处理的流类型有点严格。

我相信解决这个冲突的正确方法是从 xml 字符串中去除编码声明。

您可以为“wsgi_call”事件添加一个处理程序来实现这一点。查看事件示例以了解相关 API 的外观。


查看完整回答
反对 回复 2022-04-27
  • 2 回答
  • 0 关注
  • 167 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号