免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3771 | 回复: 2
打印 上一主题 下一主题

SOAP客户端 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-06-17 11:42 |只看该作者 |倒序浏览
本帖最后由 idhly 于 2012-06-17 12:01 编辑

现在我有这样一个情况,可以获取某个网站的Web Service描述http://localhost:1128/SAPOscol/?wsdl。从而知道其中的很多method和message/element type.

现在我想通过Python写一个客户端执行该服务描述中一些Web Service的method并解析结果(complex type),但我发现在基本库的范围内似乎SOAP的服务无法直接调用,因为python基本库里只有XMLRPC。

但我不清楚如何利用XMLRPC解析SOAP的WSDL以及如何调用。写的一段代码总是报HTTP 500 ERROR。这个SOAP调用是用Document.literal 而不是HTTP/HTTPS GET/POST方法。

  1. import xmlrpclib
  2. server = xmlrpclib.ServerProxy("http://localhost:1128/SAPOscol.cgi")
  3. try:
  4.    result = server.GetSingleCpu()
  5. except xmlrpclib.Fault, fault:
  6.    print fault.faultcode
  7.    print fault.faultstring
复制代码
结果:

  1. xmlrpclib.ProtocolError: <ProtocolError for localhost:1128/SAPOscol.cgi: 500 In
  2. ternal Server Error>
复制代码
刚开始接触Web Service,有很多地方还不太明白,谢谢

论坛徽章:
0
2 [报告]
发表于 2012-06-17 12:54 |只看该作者
单身并不难,难的是应付那些千方百计想让你结束单身的人 。

回一下

论坛徽章:
0
3 [报告]
发表于 2012-06-17 13:42 |只看该作者
本帖最后由 idhly 于 2012-06-17 13:44 编辑

刚才装了python的Suds库试了一下,很不错。

  1. from suds.client import Client
  2. url='http://localhost:1128/SAPOscol/?wsdl'
  3. client=Client(url)

  4. result = client.service.GetSingleCpu()
  5. print result
复制代码
结果

  1. C:\Temp>SysCheck.py
  2. (ArrayOfCPU){
  3.    item[] =
  4.       (CPU){
  5.          CollectionTime = 2012-06-17 13:42:15
  6.          Identifier = 0
  7.          CpuUser = 0
  8.          CpuSystem = 0
  9.          CpuIdle = 100
  10.       },
  11.       (CPU){
  12.          CollectionTime = 2012-06-17 13:42:15
  13.          Identifier = 1
  14.          CpuUser = 0
  15.          CpuSystem = 0
  16.          CpuIdle = 100
  17.       },
  18. }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP