如何在Python中显示ZSI.ServiceProxy的出站和入站SOAP消息?
问题描述:
在调用Web Service方法时,如何显示由ZSI.ServiceProxy生成的SOAP消息和Web Service的响应?
How to display a SOAP message generated by ZSI.ServiceProxy and a respond from a Web Service when a Web Service method is invoked?
答
以下是一些文档在ServiceProxy类上.构造函数接受tracefile
参数,该参数可以是具有write
方法的任何对象,因此看起来就像您想要的那样.从文档中修改示例:
Here is some documentation on the ServiceProxy class. The constructor accepts a tracefile
argument which can be any object with a write
method, so this looks like what you are after. Modifying the example from the documentation:
from ZSI import ServiceProxy
import BabelTypes
import sys
dbgfile = open('dbgfile', 'w') # to log trace to a file, or
dbgfile = sys.stdout # to log trace to stdout
service = ServiceProxy('http://www.xmethods.net/sd/BabelFishService.wsdl',
tracefile=dbgfile,
typesmodule=BabelTypes)
value = service.BabelFish('en_de', 'This is a test!')
dbgfile.close()