Cita:
Empezado por adolphsys
Probado en las tres haciendas, en server de pruebas y todo OK!
|
La semana pasada todo funcionaba bien pero ahora, en Bizkaia, me da problemas al intentar hacer la validación del fichero xml a enviar. El error se produce en la línea "schema.Add(xsdFile, xsdFile);" del siguiente código C#.
Código:
try
{
_isValid = true;
string xsdFile = "https://www.batuz.eus/fitxategiak/batuz/LROE/esquemas/LROE_PF_140_1_1_Ingresos_ConfacturaConSG_AltaPeticion_V1_0_2.xsd";
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
XmlSchemaSet schema = new XmlSchemaSet();
schema.Add(xsdFile, xsdFile);
using (XmlReader rd = XmlReader.Create(xmlFile))
{
XDocument doc = XDocument.Load(rd);
doc.Validate(schema, ValidationCallBack);
}
if (!_isValid)
{
string cpt = string.Format("Processing {0}. {1}", GetFileName(xmlFile), MethodBase.GetCurrentMethod().Name);
MessageBox.Show(_noValidInformation.TrimEnd(Environment.NewLine.ToCharArray()), cpt, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
}
return _isValid;
}
catch (WebException ex)
{
//string statuscode = string.Format("Estado: {0}. {1}", ((HttpWebResponse)ex.Response).StatusCode, ((HttpWebResponse)ex.Response).StatusDescription);
string statuscode = string.Format("Estado: {0}", ex.Status);
_error = string.Format("{0}. {1}", ex.Message, statuscode);
//MessageBox.Show(ex.Message, MethodBase.GetCurrentMethod().Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
string cpt = string.Format("WebException: Processing {0}. {1}", System.IO.Path.GetFileName(xmlFile), System.Reflection.MethodBase.GetCurrentMethod().Name);
MessageBox.Show(string.Format("{0}{1}{2}", statuscode, System.Environment.NewLine, ex.Message), cpt, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
return false;
}
catch (Exception ex)
{
//isValid = false; no need to say isValid=false as it returns false
_error = ex.Message;
//MessageBox.Show(ex.Message, .MethodBase.GetCurrentMethod().Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
string cpt = string.Format("Processing {0}. {1}", System.IO.Path.GetFileName(xmlFile), System.Reflection.MethodBase.GetCurrentMethod().Name);
MessageBox.Show(ex.Message, cpt, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
return false;
}
¿Cómo hacéis la validación del cumplimiento del esquema vosotros? Gracias.