Consuming HTTP Services in Python Transcripts
Chapter: Calling SOAP services from Python
Lecture: Concept: Using suds

Login or purchase this course to watch this video and the rest of the course contents.
0:01 So let's look at how we work with Soap services from suds in Python.
0:06 It all begins with the wsdl, as we've seen and then we can use the wsdl
0:10 plus the suds package to generate a suds proxy or suds client.
0:15 Now, this suds proxy knows all he structure and schema and operations
0:20 that the Soap web service wants to call, that the Soap web service provides.
0:25 So once we have the proxy, it knows how to do the Soap exchange
0:29 basically seamlessly to us and afterwards, we just work with this local class
0:33 that is created at runtime with suds and everything looks pretty easy, in code,
0:38 we just import the client from suds.client, we have our url to the wsdl,
0:43 and we just allocate an instance of the client class
0:48 and provided the wsdl, boom, we're done.
0:51 Now it's parsed and understood that web service description language
0:54 it gives us this client which has a service property, and on there,
0:58 we can call functions which will map dynamically to the operations on the server.
1:02 Now, you may want to know exactly what this client thinks the operations are,
1:08 so we've seen that we can just print it out and we get a really nice listing
1:13 of what the operations and rich types are, so if we print this,
1:18 we get something like this, service blog and it's going to have a couple of ports,
1:22 these are actually the various soap 1 and soap 1.2 formats
1:28 that it supports but typically they are identical,
1:31 and here our example had 5 methods and 2 rich types,
1:35 that array of posts I'd really like to see that just come back as a list
1:38 but hey, it's not that big of a deal, alright, so we have our all post,
1:42 create post, delete post, and these are normally verbs,
1:45 not nouns like we have in the http restful services,
1:48 where the verbs are actually the actions we take on the nouns,
1:51 here these are things like delete post
1:54 or create post or get me the post, stuff like that.
1:57 Once you know what the operations are and the signatures of them,
2:00 you are going to want to call those functions, right,
2:02 so we are going to make sure we've already got the client,
2:05 we've got the client created from the wsdl,
2:08 and then we just say client.service and we start calling these operations,
2:11 any time you see an array of thing, you know,
2:14 the arrays actually contained in the first element of that tuple that comes back there,
2:18 and then these come back already parsed into post objects,
2:22 so we can say post.Title and post.ViewCount.
2:25 We can also call functions that take parameters so client.service.UpdatePost
2:29 it takes a post id, title, content and a view count.