Wicked Development


Hopefully this small piece of code will save you some grief when integrating the EBAY Finding API into your application.

Here are  the Steps –

Step 1 – Create a C# Console Application and Add a Service Reference

Step 2 – Enter Code to Call findItemsByKeywords with the Ebay SOA Custom Headers

using System;

using System.ServiceModel;

using System.ServiceModel.Channels;

using EbayTestWCFConsoleApplication.EbayServiceReference;

namespace EbayTestWCFConsoleApplication

{

class Program

{

static void Main(string[] args)

{


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”, “YOUR-APPID”);

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 = “ipod”;


FindItemsByKeywordsResponse
response = client.findItemsByKeywords(request);


foreach
(var item in response.searchResult.item)

{

Console.WriteLine(item.title);

}

}

}


Console
.ReadKey();

}

}

}

Step 3 – Tweak Response Message size in App.Config and Press F5

You must change maxBufferSize=”655360” and maxReceivedMessageSize=”655360” to same ‘increased’ value.  In this example I have simply added another “0”.

<?xml version=1.0 encoding=utf-8 ?>

<configuration>

<configSections>

</configSections>

<system.serviceModel>

<bindings>

<customBinding>

<binding name=FindingServiceSOAPBinding>

<textMessageEncoding maxReadPoolSize=64 maxWritePoolSize=16

messageVersion=Soap12 writeEncoding=utf-8>

<readerQuotas maxDepth=32 maxStringContentLength=8192 maxArrayLength=16384

maxBytesPerRead=4096 maxNameTableCharCount=16384 />

</textMessageEncoding>

<httpsTransport manualAddressing=false maxBufferPoolSize=524288

maxReceivedMessageSize=655360 allowCookies=false authenticationScheme=Anonymous

bypassProxyOnLocal=false hostNameComparisonMode=StrongWildcard

keepAliveEnabled=true maxBufferSize=655360 proxyAuthenticationScheme=Anonymous

realm=“” transferMode=Buffered unsafeConnectionNtlmAuthentication=false

useDefaultWebProxy=true requireClientCertificate=false>

<extendedProtectionPolicy policyEnforcement=Never />

</httpsTransport>

</binding>

</customBinding>

</bindings>

<client>

<endpoint address=https://svcs.ebay.com/services/search/FindingService/v1

binding=customBinding bindingConfiguration=FindingServiceSOAPBinding

contract=EbayServiceReference.FindingServicePortType name=FindingServiceSOAPPort />

</client>

</system.serviceModel>

</configuration>

Please excuse the code formatting, but you’ll get the idea if you cut and paste it in.

Take Care,

Matt

using System;

using System.ServiceModel;

using System.ServiceModel.Channels;

using EbayTestWCFConsoleApplication.EbayServiceReference;

namespace EbayTestWCFConsoleApplication

{

class Program

{

static void Main(string[] args)

{

using (FindingServicePortTypeClient client = new FindingServicePortTypeClient())

{

MessageHeader header = MessageHeader.CreateHeader(“My-CustomHeader”,http://www.mycustomheader.com&#8221;,“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”, “PriceIns-e439-4e18-8678-7ecd8f6f26ba”);

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 = “ipod”;

FindItemsByKeywordsResponse response = client.findItemsByKeywords(request);

foreach (var item in response.searchResult.item)

{

Console.WriteLine(item.title);

}

}

}

Console.ReadKey();

}

}

}

After installing Visual Studio 2008 SP and .NET Framework 3.5 SP1 I tried to create and run a quick dynamic data test site and got at least the following errors –

Error 3 ‘System.Web.DynamicData.FieldTemplateUserControl.Mode’ is not supported by the language C:\Users\matt\Documents\Visual Studio 2008\Projects\DDWebApplication\DDWebApplication\DynamicData\FieldTemplates\ForeignKey_Edit.ascx.cs 37 17 DDWebApplication

Error 5 ‘System.Runtime.Serialization.DataContractAttribute’ does not contain a definition for ‘IsReference’ c:\users\matt\documents\visual studio 2008\projects\ddwebapplication1\ddwebapplication1\model1.designer.cs 286 65 DDWebApplication1

Warning 1 Reference to type ‘System.Web.UI.WebControls.DataBoundControlMode’ claims it is defined in ‘c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Web.dll’, but it could not be found c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Web.DynamicData.dll DDWebApplication1

To cut a very LONG (and brain aching) story short, my installation BELIEVED it had installed correctly with no error messages, BUT it simply had not upgraded .net framework 3.0 and 3.5 to the appropriate SP2 and SP1!!

The only way to fix this (re-installing over the top was no good) was to uninstall (when doing this you will notice that hotfixes et al are not installed in the first place) and reinstall as per this excellent guide from Aaron Stebner (who suggested this in the 1st place) –

http://blogs.msdn.com/astebner/archive/2008/08/01/8803442.aspx

If this is not your issue, here ‘some’ are Other links I travelled through in trying to fix this –

http://blogs.msdn.com/astebner/archive/2008/06/24/8649874.aspx
http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3533510&SiteID=1
http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3610934&SiteID=1
http://social.microsoft.com/Forums/en-US/whatforum/thread/d8d5bb5c-d3b1-4152-89b2-eabe306ca0bc/
http://blogs.msdn.com/astebner/archive/2008/03/03/8015158.aspx

Hope this helps save someone some grief!