For Python to invoke WebService only as a client, it is recommended to use the Suds library, which is quite lightweight and easy to use compared to zsi,soapy.
Installation suds is recommended for use with Easy_insall. Here are some of the official examples:
Python code from suds.client import client url = ' http:// Localhost:7080/webservices/webservicetestbean?wsdl ' client = client (URL) #查看该service提供的方法 print client suds - version: 0.3.3 build: (Beta) R397-20081121 service ( Webservicetestbeanservice) tns= "http://test.server.enterprise.rhq.org/" prefixes (1): ns0 = "http:// test.server.enterprise.rhq.org/" Ports (1): (Soap) Methods: addperson (person person, ) echo (xs:string arg0, ) getlist (xs:string str, xs: int length, ) getpercentbodyfat (xs: String name, xs:int height, xs:int weight) getpersonbyname (name name, ) hello () testexceptions () testlistarg (xs:string[] list, ) testvoid () updateperson (anotherperson person, name name, ) Types (: Person ) name Phone anotherperson
1. Simple parameter call
Python code result = Client.service.getPercentBodyFat (' Jeff ', 170) Print result = Client.service.getPerc Entbodyfat (name= ' Jeff ', height=68, weight=170) print result #词典 D = dict (name= ' Jeff ', height=68, weight=170) re Sult = Client.service.getPercentBodyFat (**d) print result for you have 21% body fat.
2. Complex parameters
Java Code person = client.factory.create ("person") print person
Java code (person) = { phone = [] age = NONE name (name) = { last = NONE first = NONE } }
#设置变量 java Code phone = client.factory.create (' phone ') Phone.npa = Phone.nxx = 555 Phone.number = 1212 Pytho N Code name = client.factory.create (' name ') Name.first = ' Elmer ' name.last = ' Fudd '
Python code person.name = Name Person.age = km PERSON.PHONE = [Phone]