python调用SOA服务,运用suds模块
#! /usr/bin/python # coding:gbk import suds,time,sys reload(sys) sys.setdefaultencoding( "utf-8" ) import logging logging.basicConfig(level=logging.INFO, format='%(asctime)s %(filename)s[line:%(lineno)d] 【%(levelname)s】 %(message)s', datefmt='%a, %d %b %Y %H:%M:%S', filename=r".Service"+time.strftime(r'%Y-%m-%d', time.localtime(time.time()))+".log", filemode='a') console = logging.StreamHandler() logging.getLogger('suds.client').addHandler(console) def TestService(): url='服务的WSDL链接地址' client = suds.client.Client(url) param1=dict(X='123') result1=client.service.METHODNAME1(param1) writeLog('METHODNAME1',result1) def writeLog(methodname,result): '''写日志''' content = methodname + " " for item in result: content=content+' |'+str(item) if result.Success==False: logging.error(content) else: logging.info(content) if __name__=="__main__": TestService()