using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Xsl;
using System.Configuration;
using System.Web;
using System.Net;
using System.IO;
using IDS.Rapport.Dell.Helpers;
namespace IDS.Rapport.Dell.Helpers
{
public class RapportDataImport
{
public static string RapportDataImportCall(XmlDocument RequestXmlDoc)
{
string ResponseText = "";
try
{
if (string.Equals(RequestXmlDoc.DocumentElement.Name.ToString(), "Requests"))
{
ResponseText = RapportDataImportCall_MultiApp(RequestXmlDoc);
}
else
{
// Request to IL web service
string strUrlPort = Convert.ToString(ConfigurationManager.AppSettings["RapportDataImportURL"]).Trim();
HttpWebRequest PostRequest = (HttpWebRequest)HttpWebRequest.Create(strUrlPort);
PostRequest.Method = "POST";
PostRequest.Accept = "text/xml";
PostRequest.ContentType = "text/xml;charset=\"utf-8\"";
PostRequest.Timeout = -1;
Logging.Perform_Logging(RequestXmlDoc.OuterXml, "Request_Before_Posting_To_RapportDataImport");
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byte1 = encoding.GetBytes(RequestXmlDoc.OuterXml);
PostRequest.ContentLength = byte1.Length;
Stream newStream = PostRequest.GetRequestStream();
newStream.Write(byte1, 0, byte1.Length);
newStream.Close();
// Get the response from PostRequest above
HttpWebResponse Response = PostRequest.GetResponse() as HttpWebResponse;
Stream ResponseStream = Response.GetResponseStream();
StreamReader ResponseReader = new StreamReader(ResponseStream);
ResponseText = ResponseReader.ReadToEnd();
Logging.Perform_Logging(ResponseText, "Response_From_RapportDataImport");
ResponseReader.Close();
Response.Close();
}
string FirstString = "";
string LastString = "";
if (ResponseText.Contains("<message>"))
{
FirstString = "<message>";
LastString = "</message>";
}
else
{
FirstString = "<InfoMsg>";
LastString = "</InfoMsg>";
}
ResponseText = StringHelper.Between(ResponseText,FirstString,LastString);
}
catch (Exception ex)
{
//Error Logging
ErrorHandler.WriteError(ex, "RapportDataImport.cs RapportDataImportCall");
}
finally
{
GC.Collect();
}
return ResponseText;
}
public static string RapportDataImportCall_MultiApp(XmlDocument RequestXmlDoc)
{
string ResponseText = "";
// Request to IL web service
string strUrlPort = Convert.ToString(ConfigurationManager.AppSettings["RapportDataImportURL"]).Trim();
XmlNodeList Requests = RequestXmlDoc.SelectNodes("Requests/Request");
foreach(XmlNode Request in Requests)
{
HttpWebRequest PostRequest = (HttpWebRequest)HttpWebRequest.Create(strUrlPort);
PostRequest.Method = "POST";
PostRequest.Accept = "text/xml";
PostRequest.ContentType = "text/xml;charset=\"utf-8\"";
PostRequest.Timeout = -1;
Logging.Perform_Logging(RequestXmlDoc.OuterXml, "Request_Before_Posting_To_RapportDataImport");
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byte1 = encoding.GetBytes(Request.InnerXml);
PostRequest.ContentLength = byte1.Length;
Stream newStream = PostRequest.GetRequestStream();
newStream.Write(byte1, 0, byte1.Length);
newStream.Close();
// Get the response from PostRequest above
HttpWebResponse Response = PostRequest.GetResponse() as HttpWebResponse;
Stream ResponseStream = Response.GetResponseStream();
StreamReader ResponseReader = new StreamReader(ResponseStream);
ResponseText += ResponseReader.ReadToEnd();
Logging.Perform_Logging(ResponseText, "Response_From_RapportDataImport");
ResponseReader.Close();
Response.Close();
}
return ResponseText;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Xsl;
using System.Configuration;
using System.Web;
using System.Net;
using System.IO;
using IDS.Rapport.Dell.Helpers;
namespace IDS.Rapport.Dell.Helpers
{
public class RapportDataImport
{
public static string RapportDataImportCall(XmlDocument RequestXmlDoc)
{
string ResponseText = "";
try
{
if (string.Equals(RequestXmlDoc.DocumentElement.Name.ToString(), "Requests"))
{
ResponseText = RapportDataImportCall_MultiApp(RequestXmlDoc);
}
else
{
// Request to IL web service
string strUrlPort = Convert.ToString(ConfigurationManager.AppSettings["RapportDataImportURL"]).Trim();
HttpWebRequest PostRequest = (HttpWebRequest)HttpWebRequest.Create(strUrlPort);
PostRequest.Method = "POST";
PostRequest.Accept = "text/xml";
PostRequest.ContentType = "text/xml;charset=\"utf-8\"";
PostRequest.Timeout = -1;
Logging.Perform_Logging(RequestXmlDoc.OuterXml, "Request_Before_Posting_To_RapportDataImport");
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byte1 = encoding.GetBytes(RequestXmlDoc.OuterXml);
PostRequest.ContentLength = byte1.Length;
Stream newStream = PostRequest.GetRequestStream();
newStream.Write(byte1, 0, byte1.Length);
newStream.Close();
// Get the response from PostRequest above
HttpWebResponse Response = PostRequest.GetResponse() as HttpWebResponse;
Stream ResponseStream = Response.GetResponseStream();
StreamReader ResponseReader = new StreamReader(ResponseStream);
ResponseText = ResponseReader.ReadToEnd();
Logging.Perform_Logging(ResponseText, "Response_From_RapportDataImport");
ResponseReader.Close();
Response.Close();
}
string FirstString = "";
string LastString = "";
if (ResponseText.Contains("<message>"))
{
FirstString = "<message>";
LastString = "</message>";
}
else
{
FirstString = "<InfoMsg>";
LastString = "</InfoMsg>";
}
ResponseText = StringHelper.Between(ResponseText,FirstString,LastString);
}
catch (Exception ex)
{
//Error Logging
ErrorHandler.WriteError(ex, "RapportDataImport.cs RapportDataImportCall");
}
finally
{
GC.Collect();
}
return ResponseText;
}
public static string RapportDataImportCall_MultiApp(XmlDocument RequestXmlDoc)
{
string ResponseText = "";
// Request to IL web service
string strUrlPort = Convert.ToString(ConfigurationManager.AppSettings["RapportDataImportURL"]).Trim();
XmlNodeList Requests = RequestXmlDoc.SelectNodes("Requests/Request");
foreach(XmlNode Request in Requests)
{
HttpWebRequest PostRequest = (HttpWebRequest)HttpWebRequest.Create(strUrlPort);
PostRequest.Method = "POST";
PostRequest.Accept = "text/xml";
PostRequest.ContentType = "text/xml;charset=\"utf-8\"";
PostRequest.Timeout = -1;
Logging.Perform_Logging(RequestXmlDoc.OuterXml, "Request_Before_Posting_To_RapportDataImport");
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byte1 = encoding.GetBytes(Request.InnerXml);
PostRequest.ContentLength = byte1.Length;
Stream newStream = PostRequest.GetRequestStream();
newStream.Write(byte1, 0, byte1.Length);
newStream.Close();
// Get the response from PostRequest above
HttpWebResponse Response = PostRequest.GetResponse() as HttpWebResponse;
Stream ResponseStream = Response.GetResponseStream();
StreamReader ResponseReader = new StreamReader(ResponseStream);
ResponseText += ResponseReader.ReadToEnd();
Logging.Perform_Logging(ResponseText, "Response_From_RapportDataImport");
ResponseReader.Close();
Response.Close();
}
return ResponseText;
}
}
}
Calling these functions
1. RapportDataImportCall
responsemessage = IDS.Rapport.Dell.Helpers.RapportDataImport.RapportDataImportCall(PurchaseOrders);
No comments:
Post a Comment