8

I want to extract all the methods and want to send some parameters using how can I do automation using python.

I want only methods as user input and send parameters to the method. How can I achieve this?

from suds.client import client
url="name fo the url"
client=Client(url)
Suds ( https://fedorahosted.org/suds/ )  version: 0.4 GA  build: R699-20100913

Service ( Services ) tns="http://www.altoromutual.com/bank/ws/"
Prefixes (1)
ns0 = "http://www.altoromutual.com/bank/ws/"
Ports (2):
(ServicesSoap)
 Methods (3):
    GetUserAccounts(xs:int UserId, )
    IsValidUser(xs:string UserId, )
    TransferBalance(MoneyTransfer transDetails, )
 Types (4):
    AccountData
    ArrayOfAccountData
    MoneyTransfer
    Transaction
  (ServicesSoap12)
 Methods (3):
    GetUserAccounts(xs:int UserId, )
    IsValidUser(xs:string UserId, )
    TransferBalance(MoneyTransfer transDetails, )
 Types (4):
     AccountData
    ArrayOfAccountData
    MoneyTransfer
    Transaction 
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
user3157084
  • 159
  • 1
  • 3
  • 8

1 Answers1

23

To list all the methods available in the WSDL:

>>> from suds.client import Client
>>> url_service = 'http://www.webservicex.net/globalweather.asmx?WSDL'

>>> client = Client(url_service)
>>> list_of_methods = [method for method in client.wsdl.services[0].ports[0].methods]

>>> print list_of_methods
[GetWeather, GetCitiesByCountry]

Then to call the method itself:

>>> response = client.service.GetCitiesByCountry(CountryName="France")

Note: Some simple examples are available at "Python Web Service Client Using SUDS and ServiceNow".

Following @kflaw's comment, this is how to retrieve the list of parameters that one's should pass to a method:

>>> method = client.wsdl.services[0].ports[0].methods["GetCitiesByCountry"]
>>> params = method.binding.input.param_defs(method)
>>> print params
[(CountryName, <Element:0x10a574490 name="CountryName" type="(u'string', u'http://www.w3.org/2001/XMLSchema')" />)
phaebz
  • 383
  • 5
  • 15
Ketouem
  • 3,820
  • 1
  • 19
  • 29
  • How do you know what format the values should be in that are passed to the method, like in your example, how do you know the value should be formatted as CountryName='France' and not just 'France'? – kflaw Mar 27 '15 at 20:59
  • @kflaw I've updated my answer with a way to retrieve the names and the types of the parameters. – Ketouem Mar 27 '15 at 22:21
  • thanks! I also found `temp = str(client);` gave me some additional info on the types and what is required. Unfortunately i'm still confused and think I need to talk to whoever developed the service – kflaw Mar 27 '15 at 22:28