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