1)安装suds:在命令行输入easy_install suds
2)编写webservice客户端代码,非常简单,只有2步:
创建client: client = suds.client.Client(url)
调用webservice接口提供的方法:result = client.service.方法名(参数)
示例代码:
#coding=utf-8 ''' Created on 2015-1-2 @author: kite ''' import suds #检查手机号归属地 url = 'http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl' clientPH = suds.client.Client(url) print clientPH result = clientPH.service.getMobileCodeInfo(18611217787) #这个号码是办证的,拿来测试,哈哈 print result # 返回 18611217787:北京 北京 北京联通GSM卡 print clientPH.last_received() #检查QQ是否在线 url2='http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl' clientQQ=suds.client.Client(url2) res2=clientQQ.service.qqCheckOnline(377470847) print res2 #返回:Y if __name__ == '__main__': pass
运行结果为:
Suds ( https://fedorahosted.org/suds/ ) version: 0.4 GA build: R699-20100913 Service ( MobileCodeWS ) tns="http://WebXml.com.cn/" Prefixes (1) ns0 = "http://WebXml.com.cn/" Ports (2): (MobileCodeWSSoap) Methods (2): getDatabaseInfo() getMobileCodeInfo(xs:string mobileCode, xs:string userID, ) Types (1): ArrayOfString (MobileCodeWSSoap12) Methods (2): getDatabaseInfo() getMobileCodeInfo(xs:string mobileCode, xs:string userID, ) Types (1): ArrayOfString 18611217787:北京 北京 北京联通GSM卡 <?xml version="1.0" encoding="UTF-8"?> <soap:Envelope> <soap:Body> <getMobileCodeInfoResponse xmlns="http://WebXml.com.cn/"> <getMobileCodeInfoResult>18611217787:北京 北京 北京联通GSM卡</getMobileCodeInfoResult> </getMobileCodeInfoResponse> </soap:Body> </soap:Envelope> Y
主要参考资料:http://blog.163.com/sky20081816@126/blog/static/16476102320109205195966/