Consuming HTTP Services in Python Transcripts
Chapter: Calling SOAP services from Python
Lecture: Blog Explorer: Via SOAP and Suds
0:01 So let's look at how we work with Soap services from suds in Python. It all begins with the wsdl, as we've seen and then we can use the wsdl
0:11 plus the suds package to generate a suds proxy or suds client. Now, this suds proxy knows all he structure and schema and operations
0:21 that the Soap web service wants to call, that the Soap web service provides. So once we have the proxy, it knows how to do the Soap exchange
0:30 basically seamlessly to us and afterwards, we just work with this local class
0:34 that is created at runtime with suds and everything looks pretty easy, in code,
0:39 we just import the client from suds.client, we have our url to the wsdl, and we just allocate an instance of the client class
0:49 and provided the wsdl, boom, we're done. Now it's parsed and understood that web service description language
0:55 it gives us this client which has a service property, and on there, we can call functions which will map dynamically to the operations on the server.
1:03 Now, you may want to know exactly what this client thinks the operations are,
1:09 so we've seen that we can just print it out and we get a really nice listing of what the operations and rich types are, so if we print this,
1:19 we get something like this, service blog and it's going to have a couple of ports, these are actually the various soap 1 and soap 1.2 formats
1:29 that it supports but typically they are identical, and here our example had 5 methods and 2 rich types,
1:36 that array of posts I'd really like to see that just come back as a list but hey, it's not that big of a deal, alright, so we have our all post,
1:43 create post, delete post, and these are normally verbs, not nouns like we have in the http restful services,
1:49 where the verbs are actually the actions we take on the nouns, here these are things like delete post
1:55 or create post or get me the post, stuff like that. Once you know what the operations are and the signatures of them,
2:01 you are going to want to call those functions, right, so we are going to make sure we've already got the client,
2:06 we've got the client created from the wsdl, and then we just say client.service and we start calling these operations,
2:12 any time you see an array of thing, you know, the arrays actually contained in the first element of that tuple that comes back there,
2:19 and then these come back already parsed into post objects, so we can say post.Title and post.ViewCount.
2:26 We can also call functions that take parameters so client.service.UpdatePost it takes a post id, title, content and a view count.