public bool GetDataFromWebSite()
{
bool myReturnBool = true;
try
{
System.Net.WebRequest webRequest = System.Net.WebRequest.Create(“www.WhereTheDataIs.com”);
//--------------------------------------------------------------------------------------------
// how to get your proxy from Internet Explorer
// open Internet Explorer
// Menu: Tools -> Internet Options
// Connections Tab -> Lan Settings Button
// copy and paste from "Address" text box e.g. < proxyServer.com >
//--------------------------------------------------------------------------------------------
//string ProxyServerName = "cit_fw1.cit.com";
string ProxyServerName = System.Configuration.ConfigurationManager.AppSettings["ProxyServerName"];
//--------------------------------------------------------------------------------------------
//set webRequest.Proxy
//--------------------------------------------------------------------------------------------
webRequest.Proxy = new System.Net.WebProxy(ProxyServerName, true);
//webRequest.Proxy.Credentials = CredentialCache.DefaultCredentials;
string ProxyUserName = System.Configuration.ConfigurationManager.AppSettings["ProxyUserName"];
string ProxyPassword = System.Configuration.ConfigurationManager.AppSettings["ProxyPassword"];
string ProxyDomain = System.Configuration.ConfigurationManager.AppSettings["ProxyDomain"];
webRequest.Proxy.Credentials = new System.Net.NetworkCredential(ProxyUserName, ProxyPassword, ProxyDomain);
//--------------------------------------------------------------------------------------------
//get webResponse via webRequest.GetResponse();
//--------------------------------------------------------------------------------------------
System.Net.WebResponse webResponse = webRequest.GetResponse();
//--------------------------------------------------------------------------------------------
//get streamReader via webResponse.GetResponseStream();
//--------------------------------------------------------------------------------------------
System.IO.StreamReader streamReader = new System.IO.StreamReader(webResponse.GetResponseStream());
//--------------------------------------------------------------------------------------------
//set property (and use up the forward-only streamReader)
//--------------------------------------------------------------------------------------------
_xmlResponse = streamReader.ReadToEnd();
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
// *** Validate thw XML contained in streamReader
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
// Create the XmlSchemaSet class.
//--------------------------------------------------------------------------------------------
XmlSchemaSet xmlSchemaSet = new XmlSchemaSet();
//--------------------------------------------------------------------------------------------
// Add the schema to the collection.
//--------------------------------------------------------------------------------------------
string TargetNamespace = System.Configuration.ConfigurationManager.AppSettings["TargetNamespace"];
//string MySchema = System.Configuration.ConfigurationManager.AppSettings["MySchema"];
//xmlSchemaSet.Add(TargetNamespace, new XmlTextReader(MySchema));
xmlSchemaSet.Add(TargetNamespace, new XmlTextReader("my.xsd"));
//--------------------------------------------------------------------------------------------
// Create the xmlReaderSettings class.
//--------------------------------------------------------------------------------------------
XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
xmlReaderSettings.ValidationType = ValidationType.Schema;
xmlReaderSettings.Schemas = xmlSchemaSet;
xmlReaderSettings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
//--------------------------------------------------------------------------------------------
//build stringReader from string
//--------------------------------------------------------------------------------------------
System.IO.StringReader stringReader = new System.IO.StringReader(_xmlResponse);
//--------------------------------------------------------------------------------------------
// Create the XmlReader class with xmlReaderSettings
//--------------------------------------------------------------------------------------------
//XmlReader xmlReader = XmlReader.Create(streamReader, xmlReaderSettings);
XmlReader xmlReader = XmlReader.Create(stringReader, xmlReaderSettings);
//--------------------------------------------------------------------------------------------
// Parse the XML file (streamReader).
//--------------------------------------------------------------------------------------------
while (xmlReader.Read())
{
try
{
}
catch (Exception exValidation)
{
myReturnBool = false;
_sbErrors.Append(exValidation.Message);
}
};
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
// *** convert XML contained in streamReader to dataset
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
// reload stringReader from string
//--------------------------------------------------------------------------------------------
stringReader = new System.IO.StringReader(_xmlResponse);
//--------------------------------------------------------------------------------------------
// load strong dataset from stringReader
//--------------------------------------------------------------------------------------------
_myDataSet.ReadXml(stringReader);
//--------------------------------------------------------------------------------------------
// done with webResponse
//--------------------------------------------------------------------------------------------
webResponse.Close();
}
catch (Exception ex)
{
myReturnBool = false;
string x = ex.ToString();
System.Diagnostics.Debug.WriteLine(x);
_sbErrors.Append(x);
//throw ex;
}
finally
{
}
return myReturnBool;
}