Consuming HTTP Services in Python Transcripts
Chapter: Calling SOAP services from Python
Lecture: SOAP services from a tool-based ecosystem

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Now, let's do something that might be a little bit unexpected for this Python class,
0:05 what I want to do is I want to show you what the expected experience is for the people that created Soap services, like how is this suppose to go,
0:15 and then we'll see how Python sort of fits into this world that was created for a place that is all about tooling driven infrastructure.
0:25 So here we are at the consumer services API talkPython,fm and we have our Soap service and it shows us these operations,
0:32 although you'll see that we are not really going to need to look at this list because it will completely describe them to us with the tooling,
0:39 so what you do in Soap is you start out with this thing called a wsdl a web service description language,
0:46 and let me just pull this up for you here, you can see here that we have here is what all post looks like, this is,
0:52 it takes nothing as a parameter, for the response it is going to return an array of posts, well an array of posts is a sequence of these things
1:02 called posts and then where is the post, here is the post right, so you can see this is like well not pretty and full of namespaces and junk like that,
1:11 it does describe to us basically what is suppose to happen in this exchange, and this is not meant for people, it's meant for tooling
1:20 so notice I am over here in Windows 10 and one of the frameworks that really popularized this is CSharp and .Net
1:26 so let me show you what people who created web services expected to happen, and then we'll go actually do this in Python,
1:33 so I am going to create a super simple little app here, if you don't know CSharp don't worry,
1:39 we are going to spend five lines of code on it and then we are going to be done, alright, here is our super simple application,
1:45 and this is what the people who made the Soap expected to happen, you right click and you say add service reference,
1:50 and this is something called wsf it's kind of nasty so I am going to go to this older add web reference variant here,
1:57 and I am going to just paste in that wsdl and say show me what you think this wsdl is,
2:02 okay we found this service, called Soap and actually if we go back here,
2:05 let me cancel this, if we put it in here we'll even get like a little description of it,
2:09 so here we have this service and it's a blog, it has a blog service, and here is those pieces I told you about, right,
2:16 so let's go back and not mess with that wsf stuff like I said, it's overly complicated, it's not necessary,
2:22 so here I am going to put for the service reference, notice it tries to reverse this, I'll just say this will be service, or svc, something like that.
2:29 So, when I press this button it's going to read the wsdl and generate a type from there, it's happening in here,
2:35 and you can see there is this web service, if I say show everything we can look in here and there is actually this reference thing okay,
2:43 so somewhere in here we are going to have a blog and this, it turns out it's actually the name of the class that has all the operations on it,
2:52 so don't worry about that, we are just going to come over here, and let's just suppose we want to get and list the blog post,
2:58 so I'll say var, and we create one of those and it knows where the service came from, so it knows how to get back there,
3:09 so of course new, this is not Python is it, and then I'll say var post=client and then here are all of our operations, get post,
3:18 get post async, we'll have all posts and so on, right, so we are going to call that and then we'll just say for each
3:25 and then let's just do a console writeline which is equivalent to print, we'll say something about the post as certain number of views
3:36 and then here we can just pass in post.title, notice that the thing knows all the stuff that is being passed around,
3:43 because it looked at that wsdl and it generated it, now this doesn't work in CSharp, but we got to put the numbers here,
3:51 let me put g0 so we get some comma separated pieces here and I'll just do one more right line here, all blog posts, like this,
3:58 so let's go and run this and see what we get. Boom, so look at that, it goes put and it talks to the service
4:05 easy breezy Python clients has this many number of views, and so on, maybe I wanted an N here, yeah, there is our comma separator.
4:15 Okay, so that is the expected experience right, we go over here we run the tooling, the tooling generates all the rich types
4:22 and then we call them and they kind of look like their local functions that we're calling like client.allpost but in fact, those go to the server.
4:29 Next up, we're going to see how Python fits into this world.

Talk Python's Mastodon Michael Kennedy's Mastodon