0

I have this SOAP response

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
        <ManageTerminalResponse xmlns="http://tpress.com.tx/">
            <ManageTerminalResult xmlns:a="http://schemas.data." xmlns:i="http://www.w3.org//XMLSchema-instance">
                <a:Checksum>2f28fff499684378d7fc89742773589a</a:Checksum>
                <a:Message>Success</a:Message>
                <a:ResponseCode>0000</a:ResponseCode>
                <a:ServerDate>20200105</a:ServerDate>
                <a:ServerTime>120931</a:ServerTime>
                <a:WorkKey>QlJgkae+3+Sksgta52t/FoFL2eA/eeuvu3ek6aFgSp8dGdsBrIA==</a:WorkKey>
            </ManageTerminalResult>
        </ManageTerminalResponse>
    </s:Body>
</s:Envelope>

I have created the class as shown below

{
    [XmlRoot("Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
    public class TResponse
    {
        public ResponseBody Body { get; set; }
    }
    public class ResponseBody
    {
        [XmlElement(ElementName = "ManageTerminalResponse", Namespace = "http://t.com.tw/")]
        public ManagterminalResponse ManageTerminalResponse { get; set; }
    }
    public class ManagterminalResponse
    {
        [XmlElement(ElementName = "ManageTerminalResult",Namespace = "http://schemas.datacontract.http://www.w3.org/2001/XMLSchema-instance")]
        public ManageTerminalRslt ManageTerminalResult { get; set; }
    }

    public class ManageTerminalRslt
    {
        [XmlElement(Namespace = "")]
        public string Checksum { get; set; }

        [XmlElement(Namespace = "")]
        public string Message { get; set; }

        [XmlElement(Namespace = "")]
        public string ResponseCode { get; set; }

        [XmlElement(Namespace = "")]
        public string WorkKey { get; set; }
    }
}

I need to pass the values from response to ManageTerminalRslt class. How can I perform the deserialization in .net 3.5 framework.

I referred this link. But for the XmlDeserializeFromString() says that need to upgrade the c# version to 6.0.

Help me with other function/code to perform above task.

  • Can't you create a proper proxy client for this SOAP service? If you have the wsdl you can add a service reference to your project or use svcutil.exe to generate a proxy that handles that for you. It basically just becomes a simple method call. – Crowcoder Jan 05 '20 at 12:35

1 Answers1

1

Here is working code. I had to change some of the namespaces in c# to get to work :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {

            string responseString = File.ReadAllText(FILENAME);
            StringReader sReader = new StringReader(responseString);

            XmlReader reader = XmlReader.Create(sReader);
            XmlSerializer serializer = new XmlSerializer(typeof(TResponse));
            TResponse tResponse = (TResponse)serializer.Deserialize(reader);
        }
    }
    [XmlRoot("Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
    public class TResponse
    {
        [XmlElement(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
        public ResponseBody Body { get; set; }
    }
    public class ResponseBody
    {
        [XmlElement(ElementName = "ManageTerminalResponse", Namespace = "http://tpress.com.tx/")]
        public ManagterminalResponse ManageTerminalResponse { get; set; }
    }
    public class ManagterminalResponse
    {
        [XmlElement(ElementName = "ManageTerminalResult", Namespace = "http://tpress.com.tx/")]
        public ManageTerminalRslt ManageTerminalResult { get; set; }
    }

    public class ManageTerminalRslt
    {
        [XmlElement(Namespace = "http://schemas.data.")]
        public string Checksum { get; set; }

        [XmlElement(Namespace = "http://schemas.data.")]
        public string Message { get; set; }

        [XmlElement(Namespace = "http://schemas.data.")]
        public string ResponseCode { get; set; }

        [XmlElement(Namespace = "http://schemas.data.")]
        public string WorkKey { get; set; }
    }
}
jdweng
  • 33,250
  • 2
  • 15
  • 20