private void LoadDocumentsFromContext(ref NodeDocument[] documents) { SoapContext responseSoapContext = this.requestor.ResponseSoapContext; XmlElement documentElement = responseSoapContext.Envelope.DocumentElement; Hashtable hashtable = new Hashtable(); XmlNodeList elementsByTagName = documentElement.GetElementsByTagName("content"); this.RaiseRequestorEvent("Parsing Documents"); foreach (XmlNode node in elementsByTagName) { XmlAttributeCollection attributes = node.Attributes; if (attributes["href"] == null) { throw new ApplicationException("Unable to find the href attribute in the context. Most likely because the response is not DIME. Please read the Node functional spec 1.1"); } string str = attributes["href"].Value; string innerText = node.ParentNode["name"].InnerText; hashtable.Add(innerText, str); } for (int i = 0; i < documents.Length; i++) { string str3 = (string)hashtable[documents[i].name]; DimeAttachment attachment = responseSoapContext.Attachments[str3]; byte[] buffer = new BinaryReader(attachment.Stream).ReadBytes((int)attachment.Stream.Length); documents[i].content = buffer; } }
private void cmdUpload_ServerClick(object sender, System.EventArgs e) { // Check if a file was submitted. if (Uploader.PostedFile.ContentLength != 0) { try { EmployeesServiceWse proxy = new EmployeesServiceWse(); // Create the attachment. // You can use either a file path or an open stream. string fileName = Path.GetFileName(Uploader.PostedFile.FileName); DimeAttachment attachment = new DimeAttachment(fileName, TypeFormat.MediaType, Uploader.PostedFile.InputStream); proxy.RequestSoapContext.Attachments.Add(attachment); // Upload the attachment. proxy.UploadFile(fileName); lblStatus.InnerText = "Thanks for submitting your file"; } catch (Exception err) { lblStatus.InnerText = err.Message; } } }
public void GetDataSet() { SoapContext sc = HttpSoapContext.ResponseContext; if (null == sc) { throw new ApplicationException("Only SOAP requests allowed"); } SqlConnection conn = new SqlConnection(@"data source=(local)\NetSDK;" + "initial catalog=Northwind;integrated security=SSPI"); SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM customers", conn); DataSet ds = new DataSet("CustomerDS"); da.Fill(ds, "Customers"); // dispose of all objects that are no longer necessary da.Dispose(); conn.Dispose(); MemoryStream memoryStream = new MemoryStream(1024); GZipOutputStream gzipStream = new GZipOutputStream(memoryStream); ds.WriteXml(gzipStream); gzipStream.Finish(); memoryStream.Seek(0, SeekOrigin.Begin); DimeAttachment dimeAttachment = new DimeAttachment("application/x-gzip", TypeFormatEnum.MediaType, memoryStream); sc.Attachments.Add(dimeAttachment); }
} // GetWebProxy // /// <summary> // /// Upload the document via the WebService // /// </summary> // public void uploadFilex(string strPath, string strFileToUpload) { // //Instancia o proxy do web service // UploadFileAttachment oProxy = new UploadFileAttachment(strUrlWebService); // // //Anexa o ficheiro // oProxy.RequestSoapContext.Attachments.Add(GetFileAsAttachment(strPath + @"\" + strFileToUpload)); // oProxy.RequestSoapContext.Attachments[0].Id = strFileToUpload; // // //Envia-o // string strRes = oProxy.UploadFile(); // oProxy.Dispose(); // // //Regista o documento // registerFile(strRes, strFileToUpload); // } private DimeAttachment GetFileAsAttachment(string FullPath) { FileStream stream = File.OpenRead(FullPath); DimeAttachment attach = new DimeAttachment("0", TypeFormat.MediaType, stream); return(attach); }
public static OutputData associaAllegato(InputData inputData, string pathDelFile) { OutputData outProto = new OutputData(); //<ServizioProtocollo><CodiceErrore>tipologia dell’errore</CodiceErrore><DescrizioneErrore>descrizione dell’errore</DescrizioneErrore></ServizioProtocollo><ServizioProtocollo><Segnatura>INPS.0064.22/06/2010.00022222122</Segnatura></ServizioProtocollo> string segnaturaXmlFormat = "<ServizioProtocollo><Segnatura>INPS.0064.22/06/2010.00022227772</Segnatura></ServizioProtocollo>";// string.Empty; //recupero la segnatura in formato xml da Web Service //chiamata effettiva ai Web Services. try { WsPia.Service1 wspia = new WsPia.Service1(); wspia.Url = urlWsPia; DimeAttachment dimeAttach = new DimeAttachment("image/gif", TypeFormat.MediaType, @pathDelFile); wspia.RequestSoapContext.Attachments.Add(dimeAttach); wspia.Timeout = System.Threading.Timeout.Infinite; segnaturaXmlFormat = wspia.associaAllegato(inputData.codApp, inputData.codAMM, inputData.codA00, inputData.codiceUtente, inputData.segnatura, inputData.xml); //estraggo la segnatura o il codice di errore a seconda dei casi if (segnaturaXmlFormat != null && segnaturaXmlFormat.Contains("Segnatura")) { //estraggo la segnatura in formato stringa string[] esitoArray1 = Regex.Split(segnaturaXmlFormat, "<Segnatura>"); string[] esitoArray2 = Regex.Split(esitoArray1[1], "</Segnatura>"); outProto.segnatura = esitoArray2[0]; } else if (segnaturaXmlFormat != null && segnaturaXmlFormat.Contains("CodiceErrore")) { //estraggo il codice di errore string[] erroreCodeArray1 = Regex.Split(segnaturaXmlFormat, "<CodiceErrore>"); string[] erroreCodeArray2 = Regex.Split(erroreCodeArray1[1], "</CodiceErrore>"); outProto.codiceErrore = erroreCodeArray2[0]; //estraggo la descrizione dell'errore string[] erroreDescrArray1 = Regex.Split(segnaturaXmlFormat, "<DescrizioneErrore>"); string[] erroreDescrArray2 = Regex.Split(erroreDescrArray1[1], "</DescrizioneErrore>"); outProto.descrizioneErrore = erroreDescrArray2[0]; } } catch (Exception ex) { logger.Debug("(WsPia) - Errore nella chiamata al metodo associaAllegato dei WS di INPS " + ex); } logger.Debug("xml di input per il metodo associaAllegato di INPS: " + inputData.xml); logger.Debug("xml di output del metodo associaAllegato di INPS: " + segnaturaXmlFormat); return(outProto); }
public static OutputData associaImmagine(InputData formData, string pathDelFile) { OutputData outProto = new OutputData(); //<ServizioProtocollo><Esito>1</Esito></ServizioProtocollo><ServizioProtocollo><CodiceErrore>tipologia dell’errore</CodiceErrore><DescrizioneErrore>descrizione dell’errore</DescrizioneErrore></ServizioProtocollo>"<ServizioProtocollo><CodiceErrore>tipologia dell’errore</CodiceErrore><DescrizioneErrore>descrizione dell’errore</DescrizioneErrore></ServizioProtocollo>"; string esitoXmlFormat = "<ServizioProtocollo><Esito>1</Esito></ServizioProtocollo>";// string.Empty; //recupero la segnatura in formato xml da Web Service //chiamata effettiva ai Web Services... try { WsPia.Service1 wspia = new WsPia.Service1(); wspia.Url = urlWsPia; DimeAttachment dimeAttach = new DimeAttachment("image/gif", TypeFormat.MediaType, @pathDelFile); wspia.RequestSoapContext.Attachments.Add(dimeAttach); wspia.Timeout = System.Threading.Timeout.Infinite; esitoXmlFormat = wspia.associaImmagine(formData.codApp, formData.codAMM, formData.codA00, formData.codiceUtente, formData.segnatura, formData.xml); //estraggo l'esito o il codice di errore a seconda dei casi if (esitoXmlFormat != null && esitoXmlFormat.Contains("Esito")) { //estraggo la segnatura in formato stringa string[] esitoArray1 = Regex.Split(esitoXmlFormat, "<Esito>"); string[] esitoArray2 = Regex.Split(esitoArray1[1], "</Esito>"); outProto.esito = esitoArray2[0]; } else if (esitoXmlFormat != null && esitoXmlFormat.Contains("CodiceErrore")) { //estraggo il codice di errore string[] erroreCodeArray1 = Regex.Split(esitoXmlFormat, "<CodiceErrore>"); string[] erroreCodeArray2 = Regex.Split(erroreCodeArray1[1], "</CodiceErrore>"); outProto.codiceErrore = erroreCodeArray2[0]; //estraggo la descrizione dell'errore string[] erroreDescrArray1 = Regex.Split(esitoXmlFormat, "<DescrizioneErrore>"); string[] erroreDescrArray2 = Regex.Split(erroreDescrArray1[1], "</DescrizioneErrore>"); outProto.descrizioneErrore = erroreDescrArray2[0]; } } catch (Exception ex) { logger.Debug("(WsPia) - Errore nella chiamata al metodo associaImmagine dei WS di INPS, è stata sollevata la seguente eccezione: " + ex); } logger.Debug("XML di input per il metodo associa immagine dei Ws di INPS:" + formData.xml); logger.Debug("xml di output del metodo associaImmagine di INPS: " + esitoXmlFormat); return(outProto); }
private void AddDocumentsToContext(NodeDocument[] documents) { this.SetMustUnderstand(); SoapContext requestSoapContext = this.requestor.RequestSoapContext; Hashtable hashtable = new Hashtable(); this.RaiseRequestorEvent("Parsing Documents"); for (int i = 0; i < documents.Length; i++) { DimeAttachment attachment = new DimeAttachment(); attachment.TypeFormat = TypeFormatEnum.MediaType; attachment.Type = "application/octet-stream"; attachment.Id = string.Format("Document-{0}", i); attachment.Stream = new MemoryStream(documents[i].content); requestSoapContext.Attachments.Add(attachment); hashtable.Add(documents[i].name, attachment.Id); this.RaiseRequestorEvent("Document Parsed"); } requestSoapContext.Add("hrefs", hashtable); }
/// <summary> /// Download /// </summary> /// <param name="securityToken"></param> /// <param name="transactionId"></param> /// <param name="dataflow"></param> /// <param name="documents"></param> void INetworkNodeBinding.Download(string securityToken, string transactionId, string dataflow, ref NodeDocument[] documents) { Init(); LOG.Debug("Download"); if (string.IsNullOrEmpty(transactionId)) { throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "NULL Transaction Id"); } try { SoapContext res = HttpSoapContext.ResponseContext; LOG.Debug("Getting visit"); NamedEndpointVisit visit = _service11Provider.VisitProvider.GetVisit(securityToken); ComplexContent content = new ComplexContent(); if (!string.IsNullOrEmpty(dataflow)) { content.Flow = new OperationDataFlow(dataflow); } content.Transaction = new SimpleId(transactionId); LOG.Debug("Submitting: " + content); IList <Document> wnosDocs = _service11Provider.ContentService.Download(content, visit); List <NodeDocument> wsdlDocList = new List <NodeDocument>(); if (!CollectionUtils.IsNullOrEmpty(wnosDocs)) { Dictionary <string, string> docIdList = new Dictionary <string, string>(); LOG.Debug("Spooling documents"); foreach (Document wnosDoc in wnosDocs) { NodeDocument doc = new NodeDocument(); doc.content = wnosDoc.Content; doc.type = CommonContentAndFormatProvider.ConvertTo11Enum(wnosDoc.Type); doc.name = wnosDoc.DocumentName; LOG.Debug(" doc:" + doc); DimeAttachment attachment = new DimeAttachment(); attachment.Stream = new MemoryStream(doc.content); attachment.TypeFormat = TypeFormatEnum.MediaType; attachment.Type = "application/x-gzip"; attachment.Id = Guid.NewGuid().ToString(); //Add to the the xref filter collection docIdList.Add(doc.name, attachment.Id); res.Attachments.Add(attachment); wsdlDocList.Add(doc); } //Output filter specific res.Add("hrefs", docIdList); } documents = wsdlDocList.ToArray(); } catch (Exception ex) { LOG.Error("Error while downloading", ex); throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ex); } }