次のコードを使用して、キーワードに基づいてアイテムを検索しています。
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using ConsoleApplication1.EbayServiceReference;
using System.ServiceModel;
using System.ServiceModel.Channels;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
TextWriter tw = new StreamWriter("1001.txt");
using (FindingServicePortTypeClient client = new FindingServicePortTypeClient())
{
MessageHeader header = MessageHeader.CreateHeader("My-CustomHeader", "http://www.mycustomheader.com", "Custom Header");
using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
{
OperationContext.Current.OutgoingMessageHeaders.Add(header);
HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();
httpRequestProperty.Headers.Add("X-EBAY-SOA-SECURITY-APPNAME", "myappid");
httpRequestProperty.Headers.Add("X-EBAY-SOA-OPERATION-NAME", "findItemsByKeywords");
httpRequestProperty.Headers.Add("X-EBAY-SOA-GLOBAL-ID", "EBAY-US");
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
FindItemsByKeywordsRequest request = new FindItemsByKeywordsRequest();
request.keywords = "gruen wristwatch parts -(sara,quartz,embassy,bob,robert,elephants,adidas)";
FindItemsByKeywordsResponse check = client.findItemsByKeywords(request);
int totalEntries = check.paginationOutput.totalEntries;
Console.WriteLine(totalEntries);
int totalPages = (int)Math.Ceiling((double)totalEntries / 100.00);
for (int curPage = 1; curPage <= totalPages; curPage++)
{
PaginationInput pagination = new PaginationInput();
pagination.entriesPerPageSpecified = true;
pagination.entriesPerPage = 100;
pagination.pageNumberSpecified = true;
pagination.pageNumber = curPage;
request.paginationInput = pagination;
FindItemsByKeywordsResponse response = client.findItemsByKeywords(request);
foreach (var item in response.searchResult.item)
{
Console.WriteLine(item.viewItemURL.ToString());
tw.WriteLine(item.viewItemURL.ToString());
}
}
}
}
tw.Close();
Console.WriteLine("end");
Console.ReadKey();
}
}
}
元のキーワード セットは次のとおりです。
グリューン 腕時計 パーツ -sara -quartz -embassy -bob -robert -elephants -adidas
このキーワード セットを使用すると、3 つの項目が返されます。結果はこちら
この参照FindingAPI
に従って使用するために、このようにフォーマットしました
Gruen 腕時計パーツ -(sara,quartz,embassy,bob,robert,elephants,adidas)
13 個のアイテムが返されます。3つのアイテムも返す必要があると思います。不一致の原因は何ですか?また、別の構文を使用して期待どおりの結果を得ることができますか?