Click here to Skip to main content
15,895,709 members

How to test an incoming xml file

El Dev asked:

Open original thread
I have an e-commerce site and need to communicate with another system, then that system asked me to develop a system which will be receiving an xml file means they will be sending an xml file in this format :
Request sent from CompanyA to CompanyB(This is my e-commerce website)
XML
<?xml version="1.0"?>
  <!DOCTYPE COMMAND PUBLIC "-//Ocam//DTD XML Command 1.0//EN" "xml/command.dtd">
    <COMMAND>
                <TYPE>PAYMENT</TYPE>
                <COMPANYNAME>Luku</COMPANYNAME>
                <CUSTOMERREFERENCEID>refernceNumber</CUSTOMERREFERENCEID>
                <MSISDN>msisdn</MSISDN>
                <AMOUNT></AMOUNT>
                <TXNID></TXNID>
                <STATUS></STATUS>
    </COMMAND>

and my system will parse that xml file and load it then reply to the system like this:
synchronous response sent from CompanyB back to CompanyA
XML
<?xml version="1.0">
  <!DOCTYPE COMMAND PUBLIC "-//Ocam//DTD XML Command 1.0//EN" "xml/command.dtd">
    <COMMAND>
      <TYPE>GBPHANDLER</TYPE>
      <TXNID>BP120522.1117.C00001</TXNID>
      <REFID>1357</REFID>
      <RESULT>TS</RESULT>
      <ERRORCODE>ERR123</ERRORCODE>
      <FLAG>Y</FLAG>
      <CONTENT>Content For Sending SMS</CONTENT>
      <MSISDN>09899847486</MSISDN>
      <COMPANYCODE>Luku</COMPANYCODE>
    </COMMAND>

and for that I have using the following code as shown in the code below:

C#
[WebMethod]
    public string COMMAND(string xml)
    {
        #region Load received xml and parse the values
        XmlDocument xdoc = new XmlDocument();
        xdoc.LoadXml(xml + Environment.NewLine);
        string TYPE = xdoc["COMMAND"].ChildNodes[0].InnerText;
        string COMPANYNAME = xdoc["COMMAND"].ChildNodes[1].InnerText;
        string CUSTOMERREFERENCEID = xdoc["COMMAND"].ChildNodes[2].InnerText;
        string MSISDN = xdoc["COMMAND"].ChildNodes[3].InnerText;
        string AMOUNT = xdoc["COMMAND"].ChildNodes[4].InnerText;
        string TXNID = xdoc["COMMAND"].ChildNodes[5].InnerText;
        string STATUS = xdoc["COMMAND"].ChildNodes[6].InnerText;
        #endregion

        string ERRORCODE = string.Empty;
        string RESULT = string.Empty;
        string FLAG = string.Empty;
        string CONTENT = string.Empty;

        StringBuilder sb = new StringBuilder();
        DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.GetConnection(), "[GetCheckoutInfoTest]", CUSTOMERREFERENCEID,AMOUNT);
        if (ds.Tables[0].Rows.Count &gt; 0)
        {
            //assign the values of ERRORCODE,RESULT,FLAG,CONTENT when condition is true
            RESULT = "TS";
        }
        else
        {
             RESULT = "TF";
        }

        #region write the response xml
        XmlWriter writer = XmlWriter.Create(sb);

            writer.WriteStartDocument();
            writer.WriteStartElement("COMMAND");

            writer.WriteStartElement("TYPE");
            writer.WriteValue(TYPE);
            writer.WriteEndElement();

            writer.WriteStartElement("TXNID");
            writer.WriteValue(TXNID);
            writer.WriteEndElement();

            writer.WriteStartElement("REFID");
            writer.WriteValue(CUSTOMERREFERENCEID);
            writer.WriteEndElement();

         

            writer.WriteStartElement("ERRORCODE");
            writer.WriteValue(ERRORCODE);
            writer.WriteEndElement();

            writer.WriteStartElement("FLAG");
            writer.WriteValue(FLAG);
            writer.WriteEndElement();

            writer.WriteStartElement("MSISDN");
            writer.WriteValue(MSISDN);
            writer.WriteEndElement();

            writer.WriteStartElement("CONTENT");
            writer.WriteValue(CONTENT);
            writer.WriteEndElement();

            writer.WriteStartElement("COMPANYCODE");
            writer.WriteValue(COMPANYNAME);
            writer.WriteEndElement();

            writer.WriteStartElement("AMOUNT");
            writer.WriteValue(AMOUNT);
            writer.WriteEndElement();

            writer.WriteEndElement();
            writer.WriteEndDocument();

            writer.Flush();
            #endregion

            return sb.ToString();
        

    }


Now I can test it by passing an xml file to the parameter on my webservice link and it is responding,but the problem is the system is not able to receive the response of my system when sending the xml file.
Now my question is how to test the incoming xml inorder to see if I can get the incoming xml file.Please help on that because I do not understand what is the problem.Thanks!
Tags: C#, XML, ASP.NET

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900