Download presentation
Presentation is loading. Please wait.
Published byEmmeline Byrd Modified over 8 years ago
1
The Mechanics of HTTP Requests and Responses and network connections
2
Slide 2 TELL ME ALL THAT YOU KNOW ABOUT GET AND POST! TELL ME ALL THAT YOU KNOW ABOUT MIME TYPES TELL ME ALL THAT YOU KNOW ABOUT XML
3
Slide 3 50,000 Foot Flyover Most of you have some understanding of networking and service-based. Here we will delve into the mechanics of developing “network-aware” applications that consume web services No matter the language and operating system, we make requests and process responses using a disconnected or connected protocol
4
Slide 4 Connected and Disconnected Protocols Using TCP, we establish connections and then read and write data over those connections SMTP, FTP all use TCP connections Using HTTP, we make requests and responses SOAP lives on top of HTTP Most restful applications are based on HTTP Web services We will focus our energy on HTTP layers
5
Slide 5 HTTP Requests and Responses No matter the language or development environment HTTP requests and responses work the same way We talked about the HttpRequest and HttpResponse objects in IS 360 with JavaScript PHP,.NET, Java, all have their implementations of HTTP requests and responses
6
Slide 6 HTTP Requests (Parts) Type: GET or POST Header Content-Type Content-Length Payload
7
Slide 7 HTTP Requests (ContentType)_ It appears in the HTTP header to describe the data in the payload envelope HTML XML PDF https://www.sitepoint.com/web- foundations/mime-types-complete-list/ https://www.sitepoint.com/web- foundations/mime-types-complete-list/
8
Slide 8 Requests and Responses (Other Protocols) Web services (SOAP and WSDL) are just protocols that send structured requests and get responses Often layered on top of HTTP They have different headers and an XML Content-Type We will look at these higher layers later in the next section At least how to consume Web Services
9
Slide 9 General Steps Prepare the HTTP request GET or POST Encoding Data Send the request Get the response Process the response
10
Slide 10 Java Java implements the HTTP request and response library as just another Java library (named java.net)
11
Slide 11 Java
12
Slide 12 PHP HTTP requests and responses are built in through another library There are several extension libraries too
13
Slide 13 PHP
14
Slide 14.NET
15
Slide 15 The.net Communications Framework
16
Slide 16 The.net Communications Framework
17
Slide 17 GET and POST HTTP requests are always done in one of two ways. Remember the basics from IS 360 GET arguments and data are sent via the URL as parameters POST arguments and data are sent via the HTTP header
18
Slide 18 GET and POST I’ll go through the mechanics of both using C# and demos as usual ASP Tracing helps us see how ASP builds requests and responses After you see what ASP does, we will see how to do this programatically
19
Slide 19 GET Illustration
20
Slide 20 POST Illustration
21
Slide 21 Getting at the HTTP Request and Response Data In ASP, we can get at the HTTP request, headers, form information, query strings, and server variables through predefined objects Other development environments operate similarly Request Request.Headers Request.Form Request.ServerVariabes
22
Slide 22 Getting at the Data All of these lists are of type System.Collections.Specialized.NameValueColl ection Items can be referenced by string key or ordinal index The values are text strings
23
Slide 23 Getting at the Data
24
Slide 24 You have seen how the ASP fabric implements and uses the GET and POST Now we will construct our own web requests and process them We will do so with both desktop and web applications to show that services are services It has nothing to do with a web browser Creating HTTP Requests
25
Slide 25 Why do this by hand? Because this is how services work We are automating processes through well- known services A Web service to get the weather
26
Slide 26 Ways to get data Restful GETPOSTSOAP
27
Slide 27 Preparing a GET The WebReqeust class has a method named Create to create the request. The argument contains the request URL The Method property should be set to GET or POST
28
Slide 28 Processing a GET The WebReqeust has a method named GetResponse This method sends the request and gets the response code It does not read the data Response.ContentType gets the format of the content Response.ContentLength gets the size of the data evenelope
29
Slide 29 Processing the GET Response We need to create a stream to read the data Call GetResponseStream() to get the stream for the response Create a StreamReader to get the response data Call StreamReader.ReadToEnd() to read the data stream
30
Slide 30 Processing the GET Response Execute the request and get response information
31
Slide 31 Reading the GET data Reading the HTTP response data is similar to reading a file You read a stream And you can read that stream differently into different objects
32
Slide 32 Reading the GET data (example) Use GetResponseStream() to create a StreamReader Same reader that you have used before
33
Slide 33 Preparing a POST Create a WebRequest as before Set the Method to POST Set the ContentType to describe the format of the body Add Headers to the collection Instead of calling GetResponseStream, we call GetRequestStream Write to this stream to send the HTTP message Close the writer to complete the response Then call GetResponse as before
34
Slide 34 A Post message
35
Slide 35 SOAP Encapsulates an XML document for the purpose of serialization SOAP messages are exchanged between providers and consumers SOAP is a message envelope containing an XML document Consumers send SOAP requests to providers Requests are method calls serialized into an XML document Providers send responses to consumers in the form of another XML document All of this happens behind the scenes and is not that significant to the developer
36
Slide 36 WSDL A WSDL document fully describes a Web service All methods are defined Method signatures are also defined A WSDL document is a well-formed and valid XML document A WSDL document is almost always generated automatically They become very complex very quickly.NET uses the WSDL document along with Intellisense technology to display member calling conventions (signature prototypes)
37
Slide 37 Using the Service Infrastructure You saw how to create a SOAP message by hand What a pain So we have a SOAP layer of abstraction that makes the process of a remote procedure call much easier
38
Slide 38 It’s based on a WSDL document A WSDL document describe the http://wsf.cdyne.com/WeatherWS/Weather.a smx?op=GetCityForecastByZIP http://wsf.cdyne.com/WeatherWS/Weather.a smx?op=GetCityForecastByZIP http://wsf.cdyne.com/WeatherWS/Weather.a smx?WSDL http://wsf.cdyne.com/WeatherWS/Weather.a smx?WSDL
39
Slide 39 Steps to use a service Add a service reference to the WSDL document Call the methods as ordinary methods
40
Slide 40 Add a Web Reference
41
Slide 41 Add a Web Reference
42
Slide 42 Web Service Example Looks like a local method call
43
Slide 43 Welcome to WCF We configure most “communication things”
44
Slide 44 The Role of App.Config App.Config operates similarly to Web.Config Here, it’s used to configure a Web Service All of this appears inside of We could also hardcode this
45
Slide 45 App.config (Bindings) Bindings define the transport protocol details needed for a client to communicate with a service Predefined (provided) bindings Custom bindings
46
Slide 46 App.config (Bindings) Here we bind to three different services
47
Slide 47 App.config (Endpoints) Endpoints allow clients to access a Web service Consists of An address (URL that points to the service) Name of a binding (how to communicate with the endpoint) The contract defining the methods available
48
Slide 48 Configure App.Config
49
Slide 49 Processing Data (Introduction)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.