频道直达 - 专题 - 新闻 - 技巧 - 组网 - 开发 - 安全 - web编程 - 图像 - 操作系统 - 数据库 - 教育 - 旅游 - 健康 - 时尚 - 驱动 - 软件 - 游戏 - 多媒体 - ERP - 讨论组

Python Web 服务开发者 第 5 部分: Python SOAP 库

来源: 作者: 出处:巧巧读书 2007-10-09 进入讨论组
上一页 1 2 3 4 5 6 7 下一页 
访问 http://www.qqread.com/xml-soap/c347699.html

  为运行服务器,请打开另一个命令 shell 并执行 python calendar-ws.py 。执行结束时使用 ctrl-C 杀死进程

  我们本来可以用也是用 SOAP.py 写的客户机测试服务器,但那太显而易见了。我们还是用低级 Python 编写客户机把 SOAP 响应作为 XML 字符串来构建,并发送一条 HTTP 消息。这个程序(testcal.py)在 清单 3中。

  清单 3:用 Python 核心库写的访问日历服务的客户机

 import sys, httplib
SERVER_ADDR = "127.0.0.1"
SERVER_PORT = 8888
CAL_NS = "http://uche.ogbuji.net/ws/eg/simple-cal"
BODY_TEMPLATE = """<SOAP-ENV:Envelope
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:s="http://uche.ogbuji.net/eg/ws/simple-cal"
 xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
 xmlns:xsd="http://www.w3.org/1999/XMLSchema"
 SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
>
 <SOAP-ENV:Body>
  <s:getMonth>
   <year xsi:type="xsd:integer">%s</year>
   <month xsi:type="xsd:integer">%s</month>
  </s:getMonth>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>"""
def GetMonth():
  year = 2001
  month = 12
  body = BODY_TEMPLATE%(year, month)
  blen = len(body)
  requestor = httplib.HTTP(SERVER_ADDR, SERVER_PORT)
  requestor.putrequest("POST", "cal-server")
  requestor.putheader("Host", SERVER_ADDR)
  requestor.putheader("Content-Type", "text/plain; charset="utf-8"")
  requestor.putheader("Content-Length", str(blen))
  requestor.putheader("SOAPAction", "http://uche.ogbuji.net/eg/ws/simple-car")
  requestor.endheaders()
  requestor.send(body)
  (status_code, message, reply_headers) = requestor.getreply()
  reply_body = requestor.getfile().read()
  print "status code:", status_code
  print "status message:", message
  print "HTTP reply body:
", reply_body
if __name__ == "__main__":
  GetMonth()

更多文章 更多内容请看Python实用指南Wlan组网----家庭专题Python相关文章专题,或进入讨论组讨论。
上一页 1 2 3 4 5 6 7 下一页 
收藏此文】【 】【打印】【关闭
较早的文章:XML技术与数据库的发展趋势分析

较新的文章:什么是SOAP
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
巧巧读书宗旨
相关专题
讨论组问题推荐
站内各频道最新更新文档
站内最新制作专题
热门关键字导读
Photoshop教 程照片处理 照片制作 PS快捷键 抠图
计 算 机 故 障XP系统修复
艺 术 与 设 计设计 流媒体 设计欣赏 边框
计 算 机 安 全ARP
站内频道文章精选
巧巧电脑频道编辑信箱  告诉我们您想看的专题或文章