对于python仅作为客户端调用webservice的情况,推荐使用suds库来完成,比起zsi,soapy之类,它可以说是相当轻量级,使用非常方便。

安装suds建议使用easy_insall来做。下面是官方的一些例子:

Python代码

from suds.client import Client
url = 'http://localhost:7080/webservices/WebServiceTestBean?wsdl'
client = Client(url) #查看该service提供的方法
print client Suds - version: 0.3.3 build: (beta) R397-20081121 Service (WebServiceTestBeanService) tns="http://test.server.enterprise.rhq.org/"
Prefixes (1):
ns0 = "http://test.server.enterprise.rhq.org/"
Ports (1):
(Soap)
Methods:
addPerson(Person person, )
echo(xs:string arg0, )
getList(xs:string str, xs:int length, )
getPercentBodyFat(xs:string name, xs:int height, xs:int weight)
getPersonByName(Name name, )
hello()
testExceptions()
testListArg(xs:string[] list, )
testVoid()
updatePerson(AnotherPerson person, name name, )
Types (23):
Person
Name
Phone
AnotherPerson

1.简单参数调用

Python代码  

result = client.service.getPercentBodyFat('jeff', 68, 170)
print result result = client.service.getPercentBodyFat(name='jeff', height=68, weight=170)
print result #词典
d = dict(name='jeff', height=68, weight=170)
result = client.service.getPercentBodyFat(**d)
print result You have 21% body fat.

2.复杂参数

Java代码  

person = client.factory.create('Person')
print person

Java代码

(Person)=
{
phone = []
age = NONE
name(Name) =
{
last = NONE
first = NONE
}
}

#设置变量

Java代码  

phone = client.factory.create('Phone')
phone.npa = 202
phone.nxx = 555
phone.number = 1212

Python代码

name = client.factory.create('Name')
name.first = 'Elmer'
name.last = 'Fudd'

Python代码  

person.name = name
person.age = 35
person.phone = [phone] #或者
person.phone.append(phone)

Java代码  

try:
person_added = client.service.addPerson(person)
except WebFault, e:
print e

在0.3.8以上版本还提供了更简单的调用方式,完美的json

Python代码

person = {}
#根据对象结构构造json phone = {
'npa':202,
'nxx':555,
'number':1212,
} name = {
'first':'Elmer',
'last':'Fudd'
} person['name'] = name
person['age'] = 35
person['phone'] = [phone,] try:
person_added = client.service.addPerson(person)
except WebFault, e:
print e

3.异常处理

Python代码  

client = client(url, faults=False)
result = client.service.addPerson(person)
print result
( 200, person ...)

更多可以查看官方文档:https://fedorahosted.org/suds/wiki/Documentation,里面还讲了soap头得安全认证,webservice cache等高级话题,有需要可以查看,都比较详细。

最新文章

  1. Redhat 一则关于路由及DNS配置的实例
  2. JavaScript 面向对象与原型
  3. div+css基础
  4. hdu 4033Regular Polygon(二分+余弦定理)
  5. AC题目简解-数论
  6. Upcase 将edit1中的每个字符串改为首字母大写
  7. 传统IO与NIO的比较
  8. Linux系统编程(25)——终端
  9. Amazon MWS 上传数据 (一) 设置服务
  10. window安装swagger editor
  11. windows10安装mysql-8.0.13(zip安装)
  12. Xapian使用入门
  13. 🍓 DOM常用基础知识点汇总(入门者适用) 🍓
  14. SpringBoot+mybatis:报错Fri Oct 19 14:29:24 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requiremen
  15. MySQL(Python+ORM)
  16. 简单读!Mybatis源码(一)一条select的一生
  17. js判断是否是移动端自动跳转到wap页面代码
  18. executing in nfs will not generate core dump file
  19. 了解SpringBoot
  20. Python调用nmap扫描网段主机信息生成xml

热门文章

  1. Java导出pdf文件数据
  2. csps模拟83最大异或和简单的括号序列旅行计划题解
  3. 微信sdk 隐藏右上角菜单项
  4. swoole手册
  5. SQL的语言分类
  6. [SNOI2017]遗失的答案
  7. Input:type属性
  8. LaTeX的安装
  9. CSS——div内文字的溢出部分用省略号显示
  10. 深入理解Java虚拟机(类加载机制)