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

De-serialize SOAP response payload received using .NET framework.

  • Answer ID 1751
  • Published 12/21/2010 03:24 PM
  • Updated 10/20/2013 06:41 AM
  • Permalink https://ebaydts.com/eBayKBDetails?KBid=1751

 

How to de-serialize response payload received using .NET framework.

 


  1. Add a reference to the eBay.Service.dll
  2. Read the SOAP payload received from eBay in a XML document.  
  3. Using System.Xml.Serialization we can de-seralize the payload into an object for storing of display purpose.
  4. For example, consider the GetItemTransactions SOAP payload from eBay.

The following is the code sample for converting the payload to an object using C#.NET

Code in the Program.cs file

 

private void button1_Click(object sender, EventArgs e)

{

     try

     {

        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.LoadXml(textBox1.Text.Trim());

        XmlNode nodeList = xmlDoc.SelectSingleNode(@".//*[local-name(.)='GetItemTransactionsResponse']");

        nodeList.Attributes.RemoveAll();

        string xmlStr = nodeList.OuterXml.Replace("GetItemTransactionsResponse", "GetItemTransactionsResponseType");

        GetItemTransactionsResponseType res = (GetItemTransactionsResponseType)DeserializeObject(xmlStr);

        label2.Text = "ItemID: " + res.Item.ItemID;

        label3.Text = "Title: " + res.Item.Title;

     }

     catch (Exception ex)

     {

        throw ex;

     }

}

private object DeserializeObject(string xmlStr)

{

     GetItemTransactionsResponseType responseObj = new GetItemTransactionsResponseType();

     StringReader read = new StringReader(xmlStr);

     XmlSerializer serializer = new XmlSerializer(responseObj.GetType(), strNamespace);

     XmlReader reader = new XmlTextReader(read);

     try

     {

        responseObj = (GetItemTransactionsResponseType)serializer.Deserialize(reader);

        return responseObj;

     }

     catch (Exception ex)

     {

        throw ex;

     }

     finally

     {

        reader.Close();

        read.Close();

        read.Dispose();

    }

}

 

Note:

Please see the attachment for a sample windows application which converts GetItemTransactions SOAP payload to a GetItemTransactionsResponseType object.

File Attachments

How well did this answer your question?

Answers others found helpful

Print Email This Page Delicious Digg Facebook Reddit StumbleUpon Twitter