*MultiOperationのサンプルコード(C#) [#xf3d950b] ここで紹介しているコードは[[こちらのプロキシクラス>../../../ProxyClass]]を使用しています。 MultiOperationを使ってItemSearchオペレーションとListSearchオペレーションのリクエストを一度に送信するサンプルです。TextBoxに検索するキーワードを入力します。 #code(csharp){{ <%@ Page Language="C#" %> <%@ 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 void Button1_Click(object sender, EventArgs e) { //商品検索のためのItemSearchを作成 ItemSearchRequest req1 = new ItemSearchRequest(); //検索するストアのインデックスを指定する(必須) req1.SearchIndex = "Blended"; //検索する語句を指定 req1.Keywords = TextBox1.Text; ItemSearch isc = new ItemSearch(); //あなたのAccess Key ID //AWSAccessKeyIdかSubscriptionIdのどちらかを必ず指定する isc.AWSAccessKeyId = "(あなたのAccessKeyID)"; //あなたのAssociate ID isc.AssociateTag = "dobonnet-22"; isc.Request = new ItemSearchRequest[] { req1 }; //ウィッシュリスト検索のためのListSearchを作成 ListSearchRequest req2 = new ListSearchRequest(); //Amazon.co.jpではListTypeにはWishListしか指定できない req2.ListType = ListSearchRequestListType.WishList; //リスト作成者の名前で検索する req2.Name = TextBox1.Text; req2.ResponseGroup = new string[] { "Request", "ListInfo", "ListMinimum" }; ListSearch list = new ListSearch(); //あなたのAccess Key ID list.AWSAccessKeyId = "(あなたのAccessKeyID)"; //あなたのAssociate ID list.AssociateTag = "dobonnet-22"; list.Request = new ListSearchRequest[] { req2 }; //MultiOperationの作成 MultiOperation multiOpe = new MultiOperation(); multiOpe.ItemSearch = isc; multiOpe.ListSearch = list; AWSECommerceService aws = new AWSECommerceService(); MultiOperationResponse res; try { //MultiOperationを実行し、結果を取得 res = aws.MultiOperation(multiOpe); } catch (Exception ex) { Label1.Text = "エラー:" + Server.HtmlEncode(ex.Message); return; } if (res == null) { Label1.Text = "結果を取得できませんでした。"; return; } //結果を表示 Label1.Text = ""; //商品検索の結果 Label1.Text += "<h2>商品検索の結果</h2>\n"; ItemSearchResponse res1 = res.ItemSearchResponse; if (res1 == null || res1.Items == null) { Label1.Text += "商品が見つかりませんでした。<br />\n"; } else if (res1.Items[0].Request.Errors != null) { Label1.Text += "エラー:" + res1.Items[0].Request.Errors[0].Message + "</br />\n"; } else if (res1.Items[0].Item == null) { Label1.Text += "該当する商品が見つかりませんでした。<br />\n"; } else { Label1.Text += res1.Items[0].TotalResults + " 件見つかりました。<br />\n"; Label1.Text += "<ul>\n"; foreach (Item i in res1.Items[0].Item) { //タイトル Label1.Text += "<li><a href=\"" + i.DetailPageURL + "\">" + i.ItemAttributes.Title + "</a>\n"; } Label1.Text += "</ul>\n"; } //ウィッシュリスト検索の結果 Label1.Text += "<h2>ウィッシュリスト検索の結果</h2>\n"; ListSearchResponse res2 = res.ListSearchResponse; if (res2 == null || res2.Lists == null) { Label1.Text += "リストが見つかりませんでした。<br />\n"; } else if (res2.Lists[0].Request.Errors != null) { Label1.Text += "エラー:" + res2.Lists[0].Request.Errors[0].Message + "</br />\n"; } else if (res2.Lists[0].List == null) { Label1.Text += "該当するリストが見つかりませんでした。<br />\n"; } else { //結果を表示する Label1.Text += res2.Lists[0].TotalResults + "件見つかりました。<br />"; Label1.Text += "<ul>\n"; foreach (List l in res2.Lists[0].List) { Label1.Text += "<li>" + "<a href=\"" + l.ListURL + "\">" + l.ListName + " : " + l.CustomerName + "</a>\n"; } Label1.Text += "</ul>\n"; } } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head 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:13,DOBON!,2006-10-20 (金) 02:15:06,DOBON!) |