Quantcast
Channel: Creating an XML receive/send page
Viewing all articles
Browse latest Browse all 5

Creating an XML receive/send page

$
0
0

Hi everyone,

first of all: sorry if this post might seem dumb, but I'm new to C# (I know VB, on the other hand )

I have to write an application that can receive XML's and respond to them accordingly.

I'm working on a Windows 2012 Server with IIS 8.5 on it.

I have Googled around a lot (also found topics on this site), but I'm stuck...

Let me explain: the sender of the XML's is an application from one of
our providers. When we receive an XML, we need to respond OK to it (to
acknowledge reception). after that, we respond with another type of xml,
depending on the content of the xml received.

The first step is thus receiving the XML and responding OK to it.

I have created a page (and service). When our provider sends an xml, it
seems I can receive it (the xml is stored on my server). However, the
response.xml is not sent; our provider gets the well know error
system.xml.exception line 1,....-thing. I have looked at my response.xml
with a HEX-editor, but there is no BOM in it.

I guess it is my code that is wrong.

Below the aspx.cs-page:

using

System;

using

System.Data;

using

System.Configuration;

using

System.Collections;

using

System.Web;

using

System.Web.Security;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.WebControls.WebParts;

using

System.Web.UI.HtmlControls;

using

System.IO;

using

System.Xml;

using

System.Collections.Specialized;

using

System.Text;


public

partialclassCaptureXml : System.Web.UI.Page

{

   

protectedvoid Page_Load(object sender, EventArgs e)

    {

       

Int32 len = (Int32)this.Request.InputStream.Length;

       

byte[] myData = newbyte[len];

       

this.Request.InputStream.Position = 0;

       

this.Request.InputStream.Read(myData, 0, len);

       

//write the data to the file

       

DateTime t = DateTime.Now;

       

//dt = dt.AddDays(14);

       

string timeStamp = t.Year.ToString() + "_"+ t.Month.ToString() + "_"+

        t.Day.ToString() +

"_"+ t.Hour.ToString() + "_"+ t.Second.ToString() +

       

"_"+ t.Millisecond.ToString();

       

string filepath = @"C:\CRDC\"+ GetTimeStampString() + "_1.xml";

       

//create a file steam object to write the data

       

FileStream fs = newFileStream(filepath,FileMode.Create,FileAccess.Write);

        fs.Write(myData, 0, (

int)len);

        fs.Flush();

        fs.Close();

       

string respfilepath = @"C:\CRDC\Response.xml";

       

XmlDocument doc = newXmlDocument();

        doc.Load(respfilepath);

       

string strResponse = doc.InnerText;

       

byte[] opStream1 = System.Text.Encoding.ASCII.GetBytes(strResponse.ToCharArray());

       

this.Response.ContentType = "text/xml";

       

this.Response.OutputStream.Write(opStream1, 0, opStream1.Length);

       

this.Response.Flush();

       

this.Response.Close();

    }

   

publicstaticstring GetTimeStampString()

    {

       

DateTime strReqTimeStamp = DateTime.Now;

       

string strRetTimeStamp = strReqTimeStamp.Year.ToString() +

       

""+ strReqTimeStamp.Month.ToString() +""+

            strReqTimeStamp.Day.ToString() +

""+ strReqTimeStamp.Hour.ToString() +""+

            strReqTimeStamp.Minute.ToString() +

""+ strReqTimeStamp.Second.ToString() +

           

""+ strReqTimeStamp.Millisecond.ToString();

       

return strRetTimeStamp;

    }

}

Below the content of my Response.xml

<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
  <npsoapserverresponse>
   <version xsi:type="xsd:string">01.00</version>
   <datetime xsi:type="xsd:dateTime">2015-11-18T16:03:00</datetime>
  </npsoapserverresponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>


Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles





Latest Images