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

实际上我有一个使用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 文件也有不同的命名空间


```python

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

from spyne.protocol.soap import Soap11

from spyne.server.wsgi import WsgiApplication

from spyne.model.complex import ComplexModel

from spyne.model.complex import Array

from twisted.internet import reactor

from twisted.web.server import Site

from twisted.web.wsgi import WSGIResource

from twisted.python import log



import sys

sys.path.insert(1,'../cloud-client/slicing')

import speech as t


class caps__CSoapReqBuf(ComplexModel):

    stringarray=String

    size=Integer



class caps__CSoapResponse(ComplexModel):

    __namespace__ = "spyne.examples.hello.soap"

    nRetCode=Integer

    strResponseData=String


class caps__CSoapRequest(ComplexModel):

    __namespace__ = "spyne.examples.hello.soap"

    nRequestType = Integer

    wstrRequestParam= String


class caps_CCallbackData(ComplexModel):

    __namespace__ = "spyne.examples.hello.soap"

    nPort=Integer

    strFunction = String



class 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']

慕村225694
浏览 168回答 2
2回答

开心每一天1111

我对此的解决方案是让 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.textif __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())

波斯汪

在这方面,lxml 对它认为可以处理的流类型有点严格。我相信解决这个冲突的正确方法是从 xml 字符串中去除编码声明。您可以为“wsgi_call”事件添加一个处理程序来实现这一点。查看事件示例以了解相关 API 的外观。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python