Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://www.atnf.csiro.au/vo/quanta/pythonclient1.html
Äàòà èçìåíåíèÿ: Fri Apr 8 09:22:11 2016
Äàòà èíäåêñèðîâàíèÿ: Sun Apr 10 00:48:04 2016
Êîäèðîâêà:

Ïîèñêîâûå ñëîâà: ï ï ï ï ï ï ï ï ï ï
ATNF Astronomy Web Services
ATNF Astronomy Web Services
á á Navigationá á 


á 
á 
á 
á 
á 

Building a Python client

The quickest way of getting a client up and running is to use a scripting language which has SOAP support, such as Python or Perl. I will use Python, with the SOAPpy package for web service support. SOAPpy requires fpconst and pyXML to be installed as well.

Accessing the service directly

If you know the details of the web service (namespace, functions etc) you can access it directly in a few lines in the Python interpreter:

 phoenix-104% python Python 2.1.3 (#1, Sep  7 2002, 15:29:56)  >>> from SOAPpy import SOAPProxy >>> quanta = SOAPProxy('http://phoenix:18080', namespace='urn:atnf-aips-quanta') >>> quanta.converts('10km/h','m/s') '2.77778 m/s' >>> quanta.convert_tobase('50km/s/Mpc') '1.62039e-18 s-1' 

Accessing the service using WSDL

If you don't know the details of the web service you can access it via the publicly available WSDL file. WSDL (Web Services Description Language) describes all features of the web service necessary for a client to use it (location, methods available, namespace, etc). You can use SOAPpy to consume the WSDL file and access the methods provided.

Firstly we find out what methods are provided by the service:

 phoenix-102% python Python 2.1.3 (#1, Sep  7 2002, 15:29:56)  >>> from SOAPpy import WSDL >>> quanta = WSDL.Proxy('quanta.wsdl') >>> quanta.methods.keys() [u'list_units', u'can_convert', u'has_constant', u'list_prefixes', u'has_prefix',  u'has_unit', u'converts', u'convert_tobase', u'convertf', u'convert_table'] 

Then, say we choose to use the convert_tobase function, we can enquire about its parameters as follows:

 >>> info = quanta.methods['convert_tobase'] >>> info.inparams [<SOAPpy.wstools.WSDLTools.ParameterInfo instance at 0x836a8ac>] >>> len(info.inparams) 1 >>> info.inparams[0].name u'quantity' >>> info.inparams[0].type (u'http://www.w3.org/2001/XMLSchema', u'string') 

So it takes one parameter named quantity which is of type string.

Finally we can call the service, passing in the single string required:

 >>> quanta.convert_tobase('10km/s') '10000 m/s' 

Note that the WSDL Proxy contains all the knowledge about the service location and namespace etc, so there is no need to specify any of that information. For more detailed information see the SOAPpy documentation.

á 

Webmaster
ASKAP
Public