Walkthrough Example Calling the eBay API Using SOAP from Visual Studio NET

You can extend the prior example to add the functionality to call the eBay API using SOAP. Because you are using SOAP instead of HTTP-POST, the steps to call that same Web service are quite different.

1. Reopen the eBaySample application you created in the prior example if it is not already open.

2. Add a reference to the eBay API by selecting Project O Add Web Reference. For the URL field, specify the location of the WSDL file, for example with this URL: http://developer.ebay. com/webservices/latest/eBaySvc.wsdl.

3. Click the GO button so that Visual Studio locates the eBay Web API.

5. Click the Add Reference button to add the reference to your project. Visual Studio .NET uses the WSDL file to identify the methods that are available for execution from your project.

6. Add the following procedure to Forml to the click event of the second button:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

'SOAP example

Dim strToken As String Dim strDevId As String Dim strAppId As String Dim strCertId As String

'specify credentials required to access API strToken = "Your Token Here" strDevId = "Your Dev Id Here" strAppId = "Your App Id Here" strCertId = "Your Cert Id Here"

Dim SOAPService As New ebay.eBayAPIInterfaceService SOAPService.Url = _

"https://api.sandbox.ebay.com/wsapi?callname=GetSearchResults&siteid=0&appid=" & strAppId & "version=383"

SOAPService.RequesterCredentials = New ebay.CustomSecurityHeaderType SOAPService.RequesterCredentials.eBayAuthToken = strToken

SOAPService.RequesterCredentials.Credentials = New ebay.UserldPasswordType SOAPService.RequesterCredentials.Credentials.AppId = strAppId SOAPService.RequesterCredentials.Credentials.DevId = strDevId SOAPService.RequesterCredentials.Credentials.AuthCert = strCertId

Dim Request As New ebay.GetSearchResultsRequestType Dim Response As New ebay.GetSearchResultsResponseType

'specify the search criteria Request.Query = "computer" Request.Version = "383"

'call the GetSearchResults method to run the search Response = SOAPService.GetSearchResults(Request)

Dim items As ebay.SearchResultItemType

TextBoxl.Multiline = True

'loop through the results and display the results For Each items In Response.SearchResultItemArray

TextBoxl.Text = TextBoxl.Text & "Title:" & items.Item.Title & vbCrLf TextBoxl.Text = TextBoxl.Text & "Description: " & _

items.Item.Description & vbCrLf TextBoxl.Text = TextBoxl.Text & "Item Id:" & items.Item.ItemID & _ vbCrLf & vbCrLf

Next End Sub

7. Input your Token, Dev ID, App ID, and Cert ID on the lines of code where indicated. As mentioned previously, these values are provided in the information screens provided when you set up your account.

8. Select File O Save All to save all changes to the project.

9. Select Debug O Start (or press F5) to run the project. Click the button that says SOAP Example to run the SOAP Example.

10. You should see a window similar to that shown in Figure 5-11 that displays the search results.

Notice that you were able to refer to the data elements of the API call within your code without having to parse any XML.

Figure 5-11

As new versions of the eBay API are released, some of the code in this chapter may no longer function in exactly the same way as it did in prior versions. This is certainly true of the other APIs as well, but eBay seems to release new versions more frequently than some of the others.

How To Sell Information Products On Ebay

How To Sell Information Products On Ebay

Why struggle to find thousands of quality leads to sell your info products to when Ebay has tens of millions of customers waiting right now for your product! I guarantee you that you will learn everything you need to know about selling information products on Ebay in this ebook or your money back! There are literally hundreds of ways you can make money selling information products on Ebay!

Get My Free Ebook

Post a comment