Summary
Amazon Free Web Services allows you to query and display data on the Amazon site in your application, and then we entered Yamadon, with .NET to experience Web Services.
table of Contents
Amazon Web Services Introduction
2. Experience amazon Web Services using .NET
3. Small knot
Amazon Web Services Introduction
Amazon has released Web Services that can query and display its product information, which is compatible with almost all of the language that can use HTTP and consumption HTML or SOAP-based XML.
Before using Amazon Web Services, you need to the Amazon download development package. This development package contains documentation and code samples needed by developers (http://www.amazon.com/gp/browse.html/ref=sc_fe_c_3/103 -9196653-9063038? NO = 3435361 & me = A36L942TSJ2AJA & node = 3434641)
After that, you need to get the Amazon developer's documents (https://associates.amazon.com/exec/panama/Associate/join/developer/application.html)
2. Experience amazon Web Services using .NET
There are two ways to query Amazon Web Service: Use HTTP request or with SOAP, the following uses powerful .NET to complete this Yamatson tour.
First, we need to create a simple application, it must have a text box as a query, the user calls Amazon's service in the input keyword query, then the related product title output will be found In the list box, finalize the details to another multi-line text box when the user clicks the corresponding title in the list.
Complete the above steps, we need to send two requests: KeywordRequest and AsinRequest. Asin is the abbreviation of "Amazon.com Standard Product Series", which is uniquely labeled for every Amazon product. The request is divided into two types: lightweight and heavyweight, in this application, KeywordRequest is a lightweight request, while AsinRequest is a heavyweight request. This is determined by the amount of data returned by the request.
1 Create a .NET Windows application and add the following controls in the window.
TXTSEARCH-single text box allows users to enter keywords for query
LSTRESULTS-list box, display the title obtained according to keyword
TXTDETAILS-Multi-line text box, display the item details corresponding to the title
2 introduced Amazon Web Service
Select the "Add Web Reference ..." menu item in the "Project" main menu of .NET IDE and enter "http://soap.amazon.com/schemas2/amazonwebservices.wsdl" in the address bar of the pop-up dialog. car.
1 call Amazon Web Service
After the introduction of Web Service is successful, write code to introduce the namespace of the Amazon Web Service.
[C #]
Using amazonwebservices.com.Amazon.soap;
[Vb.net]
Imports Amazonwebservices.com.amazon.soap
To implement SOAP queries, first need to create an instance of an AmazonseArchService class
[Vb.net]
DIM SRCH AS New AmazonseArchService () Each keyword query will need to create a KeywordRequest instance; each ASIN query needs to be created an AsinRequest object. Each request will return a productInfo XML document node, so you must also create a productInfo instance to retrieve the data of ProductInfo from the response.
[Vb.net]
DIM KR AS New KeywordRequest ()
Kr.DevTag = "You get the Amazon developer's documents"
Kr.Keyword = txtsearch.text
Kr.Mode = "books"
Kr.Sort = " Titlerant"
Kr.tag = "WebServices-20"
Kr.Type = "Lite"
Kr.page = "1"
DIM PI As ProductInfo = Srch.KeywordSearchRequest (KR)
DIM alldetails () as details = pi.details
The request to issue the value of the Amazon developer documents before we get to the keywordRequest object, and the result is arranged in ascending order of the title letter. Each query will return up to 10 data, so you want more data to get more queries.
[Vb.net]
IF (Pi.TotalResults> 10) THEN
Kr.page = "2"
Pi = Srch.KeywordSearchRequest (KR)
AllDetails = pi.details
END IF
2 display query results
[Vb.net]
Me.cursor = Cursors.Waitcursor
DIM I as INT16
For i = 0 to allDetails.length - 1
Lstresults.Items.Add (Product Name: "& AllDetails (i) .productname &" || Product Number: "& AllDetails (i) .asin)
NEXT
Me.cursor = cursors.default
3 display details
Use the listbox's SELECTEDEXCHANGED event to retrieve the data requested by the ASIN (product serial number).
[Vb.net]
DIM AR AS New AsinRequest ()
ar.asin = Microsoft.VisualBasic.Right (CStr (lstResults.Items (lstResults.SelectedIndex)), Len (CStr (lstResults.Items (lstResults.SelectedIndex))) - (InStr (1, CStr (lstResults.Items (lstResults. SELECTEDINDEX), "|| Product Number:") LEN ("| || Product No.:") 1)
Ar.devTag = "You get the Amazon Developer Document"
Ar.type = "Heavy"
Ar.tag = "WebServices-20"
DIM SRCH AS New AmazonsearchService ()
DIM PI As Productinfo = Srch.asinsearchRequest (ar) DIM AllDetails () AS DETAILS = Pi.Details
TXTDETAILS.TEXT = "Product Name:" & AllDetails (0) .productName & System.environment.newline
TXTDETAILS.TEXT = TXTDETAILS.TEXT & "Product Sequence Number" & AllDetails (0) .asin & System.environment.newline
Dim Strauthors () AS String = AllDetails (0) .authors
IF strauthors.lendth> 0 THEN
DIM J AS INT16
For j = 0 to Strauthors.Length - 1
txtDetails.Text = txtDetails.Text & "Author:" & strAuthors (j) & System.Environment.NewLine
NEXT
END IF
TXTDetails.text = txtdetails.text & "Category:" & AllDetails (0) .catalog & system.environment.newline
TxtDetails.text = txtdetails.text & "Publishers:" & alldetails (0). Publisher & System.Environment.newline
TxtDetails.text = txtdetails.text & "Quantity:" & alldetails (0) .collectible.newline
TxtDetails.text = txtdetails.text & "Price:" & alldetails (0) .CollectiblePrice & System.Environment.newline
TXTDETAILS.TEXT = TXTDETAILS.TEXT & "Small Pictures URL:" & AllDetails (0) .imageURLSMALL & System.Environment.newline
TXTDETAILS.TEXT = TXTDETAILS.TEXT & "Picture URL:" & alldetails (0) .imageurlmedium & System.Environment.newline
TXTDETAILS.TEXT = TXTDETAILS.TEXT & "Big Picture URL:" & AllDetails (0) .imageurllarge & System.environment.newline
4 showing the picture pointing by URL
The last few lines from the above code can see that each product is included, we can write an ImageFromamazon method to display image information above the Amazon website.
Private function imagefromamamazon (byval url as string) as image
DIM WC as new WebClient ()
Dim St AS System.io.Stream = Wc.Openread (URL) DIM IMG As Image = Image.Fromstream (ST)
St.close ()
Return IMG
END FUNCTION
ImageFromamazon method Creates a WebClient instance and requesting image data from the specified URL to the Stream object. The return value of the method is an Image type, which can directly assign the image property of the PictureBox. Then add the PictureBox control on the existing form, and then prepare the following code to place the last SelectedIndexChanged event of the listbox, you can implement the function of displaying the URL image.
[Vb.net]
Pbimage.Image = imagefromamazon (allDetails (0) .imageurlmedium) 3. Small knot
This example looks very simple, but through this example, you can help learn .NET and Web Service.