Danh mục

Dive Into Python-Chapter 12. SOAP Web Services

Số trang: 51      Loại file: pdf      Dung lượng: 0.00 B      Lượt xem: 8      Lượt tải: 0    
Hoai.2512

Hỗ trợ phí lưu trữ khi tải xuống: 35,000 VND Tải xuống file đầy đủ (51 trang) 0
Xem trước 6 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Tham khảo tài liệu dive into python-chapter 12. soap web services, công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Dive Into Python-Chapter 12. SOAP Web Services Chapter 12. SOAP Web ServicesChapter 11 focused on document-oriented web services over HTTP. The“input parameter” was the URL, and the “return value” was an actual XMLdocument which it was your responsibility to parse.This chapter will focus on SOAP web services, which take a more structuredapproach. Rather than dealing with HTTP requests and XML documentsdirectly, SOAP allows you to simulate calling functions that return nativedata types. As you will see, the illusion is almost perfect; you can “call” afunction through a SOAP library, with the standard Python calling syntax,and the function appears to return Python objects and values. But under thecovers, the SOAP library has actually performed a complex transactioninvolving multiple XML documents and a remote server.SOAP is a complex specification, and it is somewhat misleading to say thatSOAP is all about calling remote functions. Some people would pipe up toadd that SOAP allows for one-way asynchronous message passing, anddocument-oriented web services. And those people would be correct; SOAPcan be used that way, and in many different ways. But this chapter will focuson so-called “RPC-style” SOAP -- calling a remote function and gettingresults back.12.1. Diving InYou use Google, right? Its a popular search engine. Have you ever wishedyou could programmatically access Google search results? Now you can.Here is a program to search Google from Python.Example 12.1. search.pyfrom SOAPpy import WSDL# youll need to configure these two values;# see http://www.google.com/apis/WSDLFILE = /path/to/copy/of/GoogleSearch.wsdlAPIKEY = YOUR_GOOGLE_API_KEY_server = WSDL.Proxy(WSDLFILE)def search(q): Search Google and return list of {title, link, description} results = _server.doGoogleSearch( APIKEY, q, 0, 10, False, , False, , utf-8, utf-8) return [{title: r.title.encode(utf-8), link: r.URL.encode(utf-8), description: r.snippet.encode(utf-8)} for r in results.resultElements]if __name__ == __main__: import sys for r in search(sys.argv[1])[:5]: print r[title] print r[link] print r[description] printYou can import this as a module and use it from a larger program, or youcan run the script from the command line. On the command line, you givethe search query as a command-line argument, and it prints out the URL,title, and description of the top five Google search results.Here is the sample output for a search for the word “python”.Example 12.2. Sample Usage of search.pyC:diveintopythoncommonpy> python search.py pythonPython Programming Languagehttp://www.python.org/Home page for Python, an interpreted, interactive, object-oriented,extensible programming language. ... Pythonis OSI Certified Open Source: OSI Certified.Python Documentation Indexhttp://www.python.org/doc/... New-style classes (aka descrintro). Regular expressions.DatabaseAPI. Email Us. docs@python.org. (c) 2004. PythonSoftware Foundation. Python Documentation. ...Download Python Softwarehttp://www.python.org/download/Download Standard Python Software. Python 2.3.3 is thecurrent production version of Python. ...Python is OSI Certified Open Source:Pythonlinehttp://www.pythonline.com/Dive Into Pythonhttp://diveintopython.org/Dive Into Python. Python from novice to pro. Find:... It is also available in multiple languages. ReadDive Into Python. This book is still being written. ...Further Reading on SOAP * http://www.xmethods.net/ is a repository of public access SOAP webservices. * The SOAP specification is surprisingly readable, if you like that sort ofthing.12.2. Installing the SOAP LibrariesUnlike the other code in this book, this chapter relies on libraries that do notcome pre-installed with Python.Before you can dive into SOAP web services, youll need to install threelibraries: PyXML, fpconst, and SOAPpy.12.2.1. Installing PyXMLThe first library you need is PyXML, an advanced set of XML libraries thatprovide more functionality than the built-in XML libraries we studied inChapter 9.Procedure 12.1.Here is the procedure for installing PyXML: 1. Go to http://pyxml.sourceforge.net/, click Downloads, and download thelatest version for your operating system. 2. If you are using Windows, there are several choices. Make sure todownload the version of PyXML that matches the version of Python you areusing. 3. Double-click the installer. If you download PyXML 0.8.3 for Windowsand Python 2.3, the installer program will be PyXML-0.8.3.win32-py2.3.exe. 4. Step through the installer program. 5. After the installation is complete, close the installer. There will not beany visible indication of success ...

Tài liệu được xem nhiều: