python 调用 webservice

本文介绍如何使用Python通过suds库远程调用C++编写的WebService接口,并展示了具体的参数设置与返回值处理方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

python 远程调用c++的webservice接口

 

 

from suds import WebFault
from suds.client import Client   
 def get_vrm_info(self):
        
        #url 要访问的接口
        url = 'http://xxxx:6300/xxx/xxxsoap?wsdl'
        client = Client(url)
        <span style="color:#FF6666;">client.set_options(port='storeserviceSoap12')#如果用的是soap12 而不是soap则需要修改端口</span>
        #传递参数,简单的,直接传一个数据,复杂的,需要用接口文档中提供的参数类型定义一个变量
        p = client.factory.create('QueryRecordInfo')
        p.cameraindexcode='00000001001310000002'
        <span style="color:#FF0000;">p.recordtype.unsignedInt=[1]</span>
        p.starttime='2015-03-13T17:06:04.000Z'
        p.endtime='2015-03-13T17:11:04.000Z'
        p.netzoneid='1'
        #print (client)#查看接口所有的函数和类型
        #print client.last_received()#查看接口的返回值
        #获取了webservice的值
        get_info = client.service.SearchCameraRecord(p)
        #有时候可以用xml的方式直接处理返回值,但是有时候xml解析失败,需要处理文本       
        print (get_info.split('<SegmentCount>')[1]).split('</SegmentCount>')[0]

 

红色的部分说明一下,xml文档是节点嵌套的,可能比较多,这个时候就一层层写下去

<recordtype>
          <unsignedInt>unsignedInt</unsignedInt>
          <unsignedInt>unsignedInt</unsignedInt>
        </recordtype>

 <span style="color:#FF0000;">       array_int = client.factory.create('ArrayOfUnsignedInt')
        array_int.unsignedInt = [1,]</span>


以后的问题:

 返回值的读取,最好是直接xml,然后用xml访问节点即可,但是有的时候可能不行

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值