public static byte[] Send(string xmlParerDocument, string IdCliente, string Ambiente, string User) { string urlWebService; if (Ambiente == "PARER") { urlWebService = Settings.Default.HTTPEsibizioneService_PROD; } else { urlWebService = Settings.Default.HTTPEsibizioneService_PRE; } string userAgent = "Browser"; // Genera i dati della chiamata POST Dictionary <string, object> parametriPerPost = new Dictionary <string, object>(); parametriPerPost.Add("VERSIONE", "1.0"); parametriPerPost.Add("LOGINNAME ", User); parametriPerPost.Add("PASSWORD ", "qaz12PO"); parametriPerPost.Add("XMLSIP", xmlParerDocument); // Prepara la request e ottiene la response // La response o è un xml o è un byte[] con lo zip byte[] fullResponse; #if DEBUG char[] messagedebug = "<xml><message>DEBUG</message></xml>".ToCharArray(); fullResponse = Convert.FromBase64CharArray(messagedebug, 0, messagedebug.Length); #else try { HttpWebResponse webResponse = ParerSender.MultipartFormDataPost(urlWebService, userAgent, parametriPerPost); // traccia della response try { if (Properties.Settings.Default.TraceEnable == true) { StreamWriter writer = File.CreateText(@"C:\BiblosDS2010\BiblosDSParerService\Response\Resp_Status_Response.txt"); writer.Write(webResponse.StatusCode); writer.Close(); } } catch { // none } // Elabora la response BinaryReader responseReader = new BinaryReader(webResponse.GetResponseStream()); if (webResponse.ContentLength == -1) { fullResponse = responseReader.ReadBytes(100000); } else { fullResponse = responseReader.ReadBytes((int)webResponse.ContentLength); } webResponse.Close(); } catch (Exception e) { try { if (Properties.Settings.Default.TraceEnable == true) { StreamWriter writer = File.CreateText(@"C:\BiblosDS2010\BiblosDSParerService\Response\Resp_Status_Exception.txt"); writer.Write(e.Message + "\n" + e.StackTrace); writer.Close(); } } catch { // none } fullResponse = null; } #endif return(fullResponse); }
public static string Send(string xmlParerDocument, Document thisDocument, ParerContext thisContext, string Ambiente) { string urlWebService; if (Ambiente == "PARER") { urlWebService = Settings.Default.HTTPVersamentoService_PROD; } else { urlWebService = Settings.Default.HTTPVersamentoService_PRE; } string userAgent = "Browser"; // Genera i dati della chiamata POST Dictionary <string, object> parametriPerPost = new Dictionary <string, object>(); parametriPerPost.Add("VERSIONE", "1.3"); parametriPerPost.Add("LOGINNAME ", thisContext.IdCliente); parametriPerPost.Add("PASSWORD ", thisContext.UserPwd); parametriPerPost.Add("XMLSIP", xmlParerDocument); // documento principale string IDDocumento = thisDocument.Documento.IDDocumentKey(0); parametriPerPost.Add(IDDocumento, new ParerSender.FileParameter(thisDocument.Documento.BytesDocumento, IDDocumento, "binary/octetstream")); // annessi /* * if (thisDocument._Annessi.Count > 0) * { * for (int iAnnesso = 0; iAnnesso < thisDocument._Annessi.Count; iAnnesso++) * { * string IDAnnesso = thisDocument._Annessi[iAnnesso].IDDocumentKey(iAnnesso + 1); * parametriPerPost.Add(IDAnnesso, new ParerSender.FileParameter(thisDocument._Annessi[iAnnesso].BytesDocumento, IDAnnesso, "binary/octetstream")); * } * } * * // allegati * if (thisDocument._Allegati.Count > 0) * { * for (int iAllegato = 0; iAllegato < thisDocument._Allegati.Count; iAllegato++) * { * string IDAllegato = thisDocument._Allegati[iAllegato].IDDocumentKey(iAllegato + 1); * parametriPerPost.Add(IDAllegato, new ParerSender.FileParameter(thisDocument._Allegati[iAllegato].BytesDocumento, IDAllegato, "binary/octetstream")); * } * } */ // Prepara la request e ottieni la response string fullResponse; #if DEBUG fullResponse = "<xml><message>DEBUG</message></xml>"; #else try { HttpWebResponse webResponse = ParerSender.MultipartFormDataPost(urlWebService, userAgent, parametriPerPost); // Elabora la response StreamReader responseReader = new StreamReader(webResponse.GetResponseStream()); fullResponse = responseReader.ReadToEnd(); webResponse.Close(); } catch (WebException e) { fullResponse = "<xml><message>" + e.Message + "</message></xml>"; } #endif return(fullResponse); }