- 追加された行はこの色です。
- 削除された行はこの色です。
*MultiOperationのサンプルコード(VB.NET) [#de68f39e]
[[こちらのC#のコード>../../CS/MultiOperation]]をVB.NETに変換したものです。
MultiOperationを使ってItemSearchオペレーションとListSearchオペレーションのリクエストを一度に送信するサンプルです。TextBoxに検索するキーワードを入力します。
#code(vbnet){{
<%@ Page Language="VB" %>
<%@ Import Namespace="Amazon.jp.v20060913" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, _
ByVal e As EventArgs)
'商品検索のためのItemSearchを作成
Dim req1 As New ItemSearchRequest()
'検索するストアのインデックスを指定する(必須)
req1.SearchIndex = "Blended"
'検索する語句を指定
req1.Keywords = TextBox1.Text
Dim isc As New ItemSearch()
'あなたのAccess Key ID
'AWSAccessKeyIdかSubscriptionIdのどちらかを必ず指定する
isc.AWSAccessKeyId = "(あなたのAccessKeyID)"
'あなたのAssociate ID
isc.AssociateTag = "dobonnet-22"
isc.Request = New ItemSearchRequest() {req1}
'ウィッシュリスト検索のためのListSearchを作成
Dim req2 As New ListSearchRequest()
'Amazon.co.jpではListTypeにはWishListしか指定できない
req2.ListType = ListSearchRequestListType.WishList
'リスト作成者の名前で検索する
req2.Name = TextBox1.Text
req2.ResponseGroup = New String() _
{"Request", "ListInfo", "ListMinimum"}
Dim list As New ListSearch()
'あなたのAccess Key ID
list.AWSAccessKeyId = "(あなたのAccessKeyID)"
'あなたのAssociate ID
list.AssociateTag = "dobonnet-22"
list.Request = New ListSearchRequest() {req2}
'MultiOperationの作成
Dim multiOpe As New MultiOperation()
multiOpe.ItemSearch = isc
multiOpe.ListSearch = list
Dim aws As New AWSECommerceService()
Dim res As MultiOperationResponse
Try
'MultiOperationを実行し、結果を取得
res = aws.MultiOperation(multiOpe)
Catch ex As Exception
Label1.Text = "エラー:" + Server.HtmlEncode(ex.Message)
Return
End Try
If res Is Nothing Then
Label1.Text = "結果を取得できませんでした。"
Return
End If
'結果を表示
Label1.Text = ""
'商品検索の結果
Label1.Text += "<h2>商品検索の結果</h2>" + vbLf
Dim res1 As ItemSearchResponse = res.ItemSearchResponse
If res1 Is Nothing OrElse res1.Items Is Nothing Then
Label1.Text += "商品が見つかりませんでした。<br />" + vbLf
ElseIf Not (res1.Items(0).Request.Errors Is Nothing) Then
Label1.Text += "エラー:" + _
res1.Items(0).Request.Errors(0).Message + _
"</br />" + vbLf
ElseIf res1.Items(0).Item Is Nothing Then
Label1.Text += _
"該当する商品が見つかりませんでした。<br />" + vbLf
Else
Label1.Text += res1.Items(0).TotalResults + _
" 件見つかりました。<br />" + vbLf
Label1.Text += "<ul>" + vbLf
Dim i As Item
For Each i In res1.Items(0).Item
'タイトル
Label1.Text += "<li><a href=""" + i.DetailPageURL + _
""">" + i.ItemAttributes.Title + "</a>" + vbLf
Next i
Label1.Text += "</ul>" + vbLf
End If
'ウィッシュリスト検索の結果
Label1.Text += "<h2>ウィッシュリスト検索の結果</h2>" + vbLf
Dim res2 As ListSearchResponse = res.ListSearchResponse
If res2 Is Nothing OrElse res2.Lists Is Nothing Then
Label1.Text += "リストが見つかりませんでした。<br />" + vbLf
ElseIf Not (res2.Lists(0).Request.Errors Is Nothing) Then
Label1.Text += "エラー:" + _
res2.Lists(0).Request.Errors(0).Message + _
"</br />" + vbLf
ElseIf res2.Lists(0).List Is Nothing Then
Label1.Text += _
"該当するリストが見つかりませんでした。<br />" + vbLf
Else
'結果を表示する
Label1.Text += res2.Lists(0).TotalResults + _
"件見つかりました。<br />"
Label1.Text += "<ul>" + vbLf
Dim l As List
For Each l In res2.Lists(0).List
Label1.Text += "<li>" + "<a href=""" + l.ListURL + _
""">" + l.ListName + " : " + l.CustomerName + _
"</a>" + vbLf
Next l
Label1.Text += "</ul>" + vbLf
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Amazonでの商品とウィッシュリストの同時検索</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="検索" /><br />
</div>
</form>
<br />
<asp:Label ID="Label1" runat="server" EnableViewState="False">
</asp:Label>
</body>
</html>
}}
//これより下は編集しないでください
#pageinfo(,2006-10-20 (金) 01:42:19,DOBON!,2006-10-20 (金) 01:42:19,DOBON!)