For full functionality of this site it is necessary to enable JavaScript.
Here are the instructions how to enable JavaScript in your web browser.

Knowledge base

Find the answer to your question

Advanced Search PView

Search terms
Search Type
Product
Category
Language
Format
SDK
Sort by
Direction

Finding API - C#.NET code sample to call Finding API using .NET framework.

  • Answer ID 1516
  • Published 12/08/2009 04:23 AM
  • Updated 10/20/2013 06:41 AM
  • Permalink https://ebaydts.com/eBayKBDetails?KBid=1516
Product

How to call FindingService - findItemsByKeywords API from .NET framework using SOAP request 


  1. Add a web reference to the Finding API definition file
     
    http://developer.ebay.com/webservices/Finding/latest/FindingService.wsdl
  2. Create a class that derives from FindingService class. For example, “CustomFindingService.cs”. Override the GetWebRequest method and set the HTTP request headers such as globalID, protocol, appName, operationName, serviceName and version.    
  3. Create an object for the required request type. For example,
       FindItemsByKeywordsRequest request = new FindItemsByKeywordsRequest();  
  4. Provide value for the required properties.
        request. keywords = “canon”; // for example 
  5. Create an object to the required response type. For example,
       FindItemsByKeywordsResponse response = service.findItemsByKeywords(request);  
  6. Explore the response object for response data.    

The following is the code sample for findItemsByKeywords API call using C#.NET

 

Code in the Program.cs file

using System;

using System.Collections.Generic;

using System.Text;

using FindingAPI_Sample.com.ebay.developer;

 

namespace FindingAPI_Sample

{

    class Program

    {

        static void Main (string[] args)

        {

            try

            {

                // Creating an object to the BestMatchService class

                CustomFindingService service = new CustomFindingService();

                service.Url = "http://svcs.ebay.com/services/search/FindingService/v1";

 

                // Creating request object for FindBestMatchItemDetailsByKeywords API

                FindItemsByKeywordsRequest request = new FindItemsByKeywordsRequest();

                // Setting the required property values

                request.keywords = "canon";

 

                // Setting the pagination

                PaginationInput pagination = new PaginationInput();

                pagination.entriesPerPageSpecified = true;

                pagination.entriesPerPage = 25;

                pagination.pageNumberSpecified = true;

                pagination.pageNumber = 1;

                request.paginationInput = pagination;

 

                // Creating response object

                FindItemsByKeywordsResponse response = service.findItemsByKeywords(request);

                SearchResult result = response.searchResult;

                Console.WriteLine("Find items results");

 

                // Looping through response object for result

                foreach (SearchItem item in result.item)

                {

                    Console.WriteLine("Item ID: " + item.itemId);

                    Console.WriteLine("Item Title: " + item.title);

                    Console.WriteLine("-------------------------------------------");

                }

            }

            catch (Exception ex)

            {

                Console.WriteLine("* Error: " + ex.Message);

            }

            Console.WriteLine("Press ENTER key to exit...");

            Console.ReadLine();

        }

    }

}

 

Code in the CustomFindingService.cs file

using System;

using System.Collections.Generic;

using System.Text;

using FindingAPI_Sample.com.ebay.developer;

using System.Net;

 

namespace FindingAPI_Sample

{

    class CustomFindingService : FindingService

    {

        protected override System.Net.WebRequest GetWebRequest(Uri uri)

        {

            try

            {

                HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(uri);

                request.Headers.Add("X-EBAY-SOA-SECURITY-APPNAME", "YOUR_APP_ID_HERE");

                request.Headers.Add("X-EBAY-SOA-OPERATION-NAME", "findItemsByKeywords");

                request.Headers.Add("X-EBAY-SOA-SERVICE-NAME", "FindingService");

                request.Headers.Add("X-EBAY-SOA-MESSAGE-PROTOCOL", "SOAP11");

                request.Headers.Add("X-EBAY-SOA-SERVICE-VERSION", "1.0.0");

                request.Headers.Add("X-EBAY-SOA-GLOBAL-ID", "EBAY-US");

                return request;

            }

            catch (Exception ex)

            {

                throw ex;

            }

        }

    }

}

 

Note:

Please see the attachment for a sample web application to make findItemsByKeywords API call.

 

 

Attachment Details:

The web application is created with using Microsoft Visual Studio 2005. Please read the README.txt before running the sample.

File Attachments

How well did this answer your question?

Answers others found helpful

Print Email This Page Delicious Digg Facebook Reddit StumbleUpon Twitter