python 调用 webservice

来源:互联网 发布:mac book 用什么vpn 编辑:程序博客网 时间:2024/06/06 18:26

 

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

 

 

from suds import WebFaultfrom 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访问节点即可,但是有的时候可能不行

0 0