…[portions omitted]… Notice that details about the ItemSearchand
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services
The general steps for calling a Web service using SOAPfrom the .NET Framework (without using VisualStudio .NET) include the following: 1.Using a text editor (such as Notepad), create all or part of the .NET program where you want touse the Web service. 2.Create a Web Service Proxy Class DLLmanually using the WSDL.EXEcommand line tool. 3.Revise the .NET program to import the namespace of the Web Service Proxy Class DLLcreatedin Step 2.4.Revise the .NET program to include the lines of code that call one or more functions of the Webservice. The general steps for calling a Web service using SOAPfrom Visual Studio .NET include the following: 1.Create a new project in Visual Studio .NET. 2.Add a Web Reference to point to the Web service you wish to call. 3.Add code in your program to create an instance of the class representing the Web service, andthen call the appropriate methods in the Web service. Walkthrough Example Calling a Web Service Using SOAP from Visual Studio .NETNow that you have been introduced to some basic concepts, let s walk through a step-by-step exampleof using SOAPand WSDLto call a Web service from Visual Studio .NET. In this example, you call thesame Amazon Web service with the same search criteria that you saw in the REST examples earlier inthis chapter. Because this example uses SOAPand Visual Studio.Net, the steps are quite different to callthat same Web service. Note that you need to obtain your own Amazon Web API Associate ID/Developer ID if you want torun the following example yourself. You can find more details about how to obtain an AmazonAssociate ID in Chapter 4.1.Open Visual Studio .NET. 2.Select File.New.Project, and select Windows Application as the type of project. 3.Specify TestAmazonWebServiceor another suitable name for the Name and change the projectlocation if desired. Then click OK. 4.Select Project.Add Web Reference, as shown in Figure 1-2.5.Ascreen like the one shown in Figure 1-3 is then displayed to allow you to specify the Web service to which you want to add a reference. 8Chapter
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Inexpensive Web Hosting services
Invoking a Web Service Using HTTP-POSTHTTP-POSTis very similar to HTTP-GET, but also introduces additional complexities and advantages. When you call a Web service using HTTP-POST, you actually post an XMLdocument that containstherequired information for calling the Web service. HTTP-POST then returns an XMLdocument inresponse. HTTP-POST can be used for data retrieval as well as updates, and it is better for transmittingsensitive information than REST, which sends the information in clear text in a URL. The steps for calling a Web service using HTTP-POST are summarized as follows: 1.Identify the Web service you would like to call and the parameters it accepts. 2.Formulate an XMLdocument containing the parameters. 3.Use your programming language of choice to call the HTTP-POST command to POST the to the desired Web service. 4.Receive the results in an XMLdocument and parse the document using an XMLparsing methodof choice. The following code segment illustrates an example of using HTTP-POST to interact with a Web API. Dim web As New System.Net.WebClientDim strXML As StringstrXML = Your XML Document Here add the xml string to the byte arrayDim d As Byte() = System.Text.Encoding.ASCII.GetBytes(strXML) call the api and pass the byte array containing the XML stringDim res As Byte() = web.UploadData( URLForAPI , POST , d) display the results in a message boxMsgBox(System.Text.Encoding.ASCII.GetString(res)) As you will see later in this book, eBay supports the HTTP-POST method as well as SOAP, which isdescribed next. Invoking a Web Service Using SOAPAnother way to call an XMLWeb service is using SOAP. SOAPstands for Simple Object Access Protocoland is an XML-based protocol for exchanging structured and type information over the Internet. SOAP, unlike HTTP-GET and HTTP-POST, supports both simple and complex types. Thus, complex types datasets, structs, and classes can be used in SOAPcommunications. SOAPis the primary message mat used by the .NET Framework for communicating with XMLWeb services. The following is an example of a SOAPdocument that calls a function named getUserInfoon a Webservice located on arcweb.esri.com to retrieve user info for the specified token.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Inexpensive Web Hosting services
Figure 1-1The steps for calling a Web service using REST are summarized as follows: 1.Identify the Web service you would like to call and the parameters it accepts. 2.Formulate the URLcontaining the parameters. 3.Test the URLfrom a Web browser to ensure it works correctly. 4.Use your programming language of choice to call the HTTP-GET command with the URL. 5.Receive the results in an XMLdocument and parse the document using an XMLparsing methodof choice. Despite the advantages of REST, it also has limitations. For example, you do not want to use REST whenyou need to transmit sensitive data because you do not want to include sensitive data in a text URL. Also, the URLhas a size limit, so REST does not work for all Web APIs. Because REST is performing aHTTP-GET (data retrieval only) operation, it cannot be used to post data. It can still be used to updatedata as long as the values in the URLdo not exceed the maximum allowed length. Let s now look atanother way of invoking a Web service using HTTP-POST. 4Chapter
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services
As you can see from the previous code example, this is a contact record with two contacts, John Doe Doe. For each contact, a contact type and a first and last name are specified. This XMLdocumentcan be sent to a mainframe, a Windows computer, a UNIX computer, and a Linux computer. All thesecomputers can read it because it is a text file. Invoking an XML Web ServiceAvery important aspect of communicating with a Web service is how you can physically execute a ified function. XMLWeb services are based on standard Internet protocols and allow you to invoke through communication mechanisms such as HTTP-GET, HTTP-POST, or SOAP over HTTP, in more detail in the following sections. Some Web APIs covered in this book, such as Amazon sWeb API, support both the HTTP-GET and SOAPoptions, although others support only one method. Web service providers can enable all three methods, but they typically disable one or more that theydecide are not appropriate or desirable for various reasons. The fact that vendors support differentmethods is the subject of much debate. You should, however, understand how to use each method can work with the various Web APIs that are available. The methods are introduced here, but I them in greater detail in the chapters that follow. Invoking a Web Service Using REST (HTTP-GET) RESTstands for Representational State Transfer.It refers to invoking a Web service using parametersincluded in a URL. REST uses HTTP-GET to retrieve data and is not typically used for data updates. After a request is processed, REST returns an XMLdocument. Let s look at an example of calling an Amazon Web service using REST. Suppose you have thefollowingURL: http://aws- beta.amazon.com/onca/xml?Service=AWSProductData&SubscriptionId=YOUR_ID_GOES_HERE&ItemSearch&SearchIndex=Books&Keywords=Denise%20GosnellNotice how the first part of the URLcontains the traditional domain information. Next, you see the ous parameters being passed. These parameters are being passed to an Amazon API (currently version4.0 beta). The URLincludes a parameter for the service being called (AWSProductData), the subscriptionID (your developer token), the operation to perform (a search), the search index to use (books), and to search on (Denise Gosnell). Parameters are separated by ampersands (&), and spaces areindicated by %20. As you can see, it is really quite easy to call a Web service using REST, if the Web service supports REST. You can then use your programming language of choice to execute the HTTP-GET command containingthe URLand process the XMLfile that is returned. You will see examples of this in action throughoutthebook. It is very easy to test a REST Web service from your Web browser. Pasting the URLlisted previously Web browser returns results similar to those shown in Figure 1-1.3Anatomy
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services
In the most generic sense, a Web service is merely a function or procedure that can be called over theInternet. This generic definition includes Web services that can be called only from specific platforms, such as Windows, and only after installation of certain software on the client. However, in the context ofthis book, the term Web servicerefers to services that are platform-neutral and so can be called from anyplatform capable of communicating using standard Internet protocols. These platform-neutral Web serv- ices are sometimes referred to as XMLWeb servicesbecause XMLis typically the data transfer formatused for them. XMLis a text-based syntax that can be understood by various platforms, as I discuss in alater section. Despite common misconceptions, XMLWeb services can be called from applications thatare not browser-based, such as traditional Windows applications. As long as the application can commu- nicate using Internet protocols, non-Web based applications can make use of the same functionality. Despite the great value of Web services, their adoption industry-wide has been slow in coming. Thegreat news is that, as of this writing, Web APIs and Web services have finally been adopted by big play- ers in the industry. Industry leaders such as Google, Amazon, and eBay have embraced the Web servicesconcept and have created Web APIs that enable you to implement their core features in your own appli- cations. This recent movement toward Web APIs is my primary reason for writing this book. In it, youwill, of course, explore several leading Web APIs to learn how you can use them in your applications. As you will see in the following chapters, most of these leading Web APIs require you to obtain a devel- oper token that must be included in each request. Vendors require a developer token in order to controlhow much you use (and thus not abuse) the service and/or how much they should charge you. MostWeb APIs have a free limited-use license or trial period, and some of them require payment for the service. Web APIs as XML Web ServicesAs I mentioned previously, Web APIs are typically a related collection of Web services. Most of the Webservices available today are based on XMLand can, therefore, be called from various platforms. Thefocus of this book is primarily on XMLWeb services. Therefore, a brief explanation on XMLis appropri- ate before you learn the basics of calling XMLWeb services in your programs. What Is XML? XMLstands for eXtensible Markup Language, which is a text-based markup language. XMLis similar toHTMLin many ways, such as how it describes data by using tags. Avery simple example of an XMLdocument is shown here. < ?xml version= 1.0 encoding= UTF-8 ?>
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services
Anatomy of a Web APIIn this chapter, you will learn the basic concepts of Web APIs that I use throughout the rest of thebook. Web APIs are application programming interfaces that can be called over standard Internetprotocols. Many companies are using Web APIs to expose functionality in their existing systemsina platform-neutral manner. Other companies are building applications from the ground up asWeb APIs. Web APIs generally allow remote computers on different platforms to talk to eachotherusing methods that were previously very difficult. This chapter will specifically cover thefollowing: .What a Web API is and how it differs from a Web service .The current status of Web APIs in the industry .Calling a Web API using REST (HTTP-GET) .Calling a Web API using HTTP-POST .Calling a Web API using HTTPand SOAPWeb APIs versus Web ServicesWeb APIs are application programming interfaces that are available over the Internet. They arealso sometimes referred to as Web services. It is helpful to think of a Web API as a series of Webservices, each of which has one or more procedures that can be called using the Internet. An exam- ple of a Web API includes the Google API, which makes various search functions available overthe Internet for use in third-party applications. Although Web APIs and Web services are separateconcepts, it is common and acceptable to refer to the two concepts interchangeably because theyare so closely related.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services
Powered by Java Web Hosting