public object Consultar(string protocolo) { //DocumentoXml documento = _repository.Get(3); string xml = @"<ConsultarLoteRpsEnvio xmlns=""http://www.publica.inf.br""><Prestador id=""assinar""><Cnpj>79011862000170</Cnpj><InscricaoMunicipal>8178</InscricaoMunicipal></Prestador><Protocolo>" + protocolo + "</Protocolo></ConsultarLoteRpsEnvio>"; var caminhoCertificado = Path.Combine(Directory.GetCurrentDirectory(), "certificado.pfx"); var certificate = new X509Certificate2(caminhoCertificado, "QUESTOR1234"); string Signature = XmlUtils.GetSignature(XmlUtils.GetXmlDocument(xml), "assinar", certificate); xml = xml.Replace("</Prestador>", "</Prestador>" + Signature); SoapWebService soap = new SoapWebService("http://nfse1.publica.inf.br/chapeco_nfse_integracao/Services?wsdl", certificate); string resultSoap = soap.ExecuteMethod <string>("ConsultarLoteRps", new object[] { xml }); resultSoap = JsonConvert.SerializeXmlNode(XmlUtils.GetXmlDocument(resultSoap.Replace(@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?>", ""))); return(resultSoap); }
public string Emissao(NfseTransmitirLote lote) { DocumentoXml documento = _repository.Get(4); string testeSerilize = XmlUtils.Serializar(lote, true); byte[] byteArray = Encoding.ASCII.GetBytes(testeSerilize); MemoryStream stream = new MemoryStream(byteArray); var oldDocument = XDocument.Load(stream); string xml = processarXml(documento.Xml, oldDocument).ToString(); XmlDocument docAlimentado = new XmlDocument(); docAlimentado.LoadXml(xml.ToString()); var certificate = new X509Certificate2(Path.Combine(Directory.GetCurrentDirectory(), "certificado.pfx"), "QUESTOR1234"); XmlNodeList nodeAssinatura = docAlimentado.GetElementsByTagName("Assinatura"); for (int i = (nodeAssinatura.Count - 1); i >= 0; i--) { XmlNode item = nodeAssinatura.Item(i); XmlDocument xmlSignature = XmlUtils.GetXmlDocument(XmlUtils.GetSignature(XmlUtils.GetXmlDocument(item.InnerXml), item.FirstChild.Attributes["id"].Value, certificate)); XmlNode Signature = item.OwnerDocument.ImportNode(xmlSignature.DocumentElement, true); XmlNode XmlAssinado = item.OwnerDocument.ImportNode(XmlUtils.GetXmlDocument(item.InnerXml).DocumentElement, true); item.ParentNode.AppendChild(XmlAssinado); item.ParentNode.AppendChild(Signature); var xml_node = docAlimentado.GetElementsByTagName("Assinatura")[i]; xml_node.ParentNode.RemoveChild(xml_node); } xml = docAlimentado.InnerXml; SoapWebService soap = new SoapWebService("http://nfse1.publica.inf.br/chapeco_nfse_integracao/Services?wsdl", certificate); var resultSoap = soap.ExecuteMethod <string>("RecepcionarLoteRps", new object[] { xml }); return(JsonConvert.SerializeXmlNode(XmlUtils.GetXmlDocument(resultSoap.Replace(@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?>", "")))); }
public HomeController(SoapWebService db) { _db = db; }
public HomeController() { _db = new SoapWebService(); }
/// <summary> /// 处理请求的xml数据 /// </summary> /// <param name="strXml"></param> /// <returns></returns> private string DealXML(string strXml) { sysLog.WriteOptDisk(strXml); //string strResponse = "<AddInfoResponse xmlns=\"http://tempuri.org/\"><AddInfoResult><?xml version=\"1.0\" encoding=\"UTF-8\"?><int xmlns =\"http://tempuri.org/\">{0}</int></AddInfoResult></AddInfoResponse>"; //string strResponse = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><int xmlns=\"http://tempuri.org/\">{0}</int>"; string strResponse = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><soap:Body>" + "<AddInfoResponse xmlns=\"http://tempuri.org/\">" + "<AddInfoResult>{0}</AddInfoResult>" + "</AddInfoResponse>" + "</soap:Body>" + "</soap:Envelope>"; string strKey = ""; try { //1 先得到para参数 XmlDocument allXml = new XmlDocument(); allXml.LoadXml(strXml);//加载xml XmlNamespaceManager man = new XmlNamespaceManager(allXml.NameTable); man.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope/"); //Querying XmlNode titlenode = allXml.SelectSingleNode("/soapenv:Envelope/soapenv:Body", man); string strPara = titlenode.InnerXml; //得到para参数值 // strPara = HttpUtility.HtmlDecode(strPara);//html解码 XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(strPara); XmlNodeList nodes = xmlDoc.ChildNodes; // DataTable dtPara = new DataTable(); string intNum = ""; // string title = ""; //标题 string content = ""; //内容 string redeptid = ""; //部门id Hashtable hashParam = new Hashtable(); // foreach (XmlNode xnode in nodes) { List <object> objList = new List <object>(); XmlNodeList listParam = xnode.ChildNodes; foreach (XmlNode nd in listParam) //遍历得到具体参数 { string strCol = nd.Name; if (strCol.Equals("intNum")) { intNum = nd.InnerText; } else if (strCol.Equals("title")) { title = nd.InnerText; } else if (strCol.Equals("content")) { content = nd.InnerText; } else if (strCol.Equals("redeptid")) { redeptid = nd.InnerText; } hashParam.Add(strCol, nd.InnerText); objList.Add(nd.InnerText); } // dtPara.Rows.Add(objList.ToArray()); } //一路插入本地数据库 //获取交办单位在新民意中对应的guid string depguid = string.Empty; string depsql = "select gid from TRAFFIC_DEPARTMENT t where id='2341'"; DataSet depDS = DbHelperOra.Query(depsql); if (depDS != null && depDS.Tables[0] != null && depDS.Tables[0].Rows.Count > 0) { depguid = depDS.Tables[0].Rows[0][0].ToString(); } if (!string.IsNullOrEmpty(depguid)) { try { #region 民意档案 string con_guid = Guid.NewGuid().ToString("N").ToUpper(); //民意档案id AddJLYEE(con_guid, title, content, intNum); #endregion #region 交办 string assign_guid = Guid.NewGuid().ToString("N").ToUpper();//交办id AddAssign(assign_guid, con_guid, depguid); #endregion #region 处办 string inwork_guid = Guid.NewGuid().ToString("N").ToUpper();//处办id AddInwork(inwork_guid, assign_guid, depguid); #endregion sysLog.WriteOptDisk("录入成功"); } catch (Exception e) { sysLog.WriteOptDisk("添加新民意数据异常【error】" + e.Message + e.StackTrace); } } else { sysLog.WriteOptDisk("未获取到交办单位guid"); } // 一路请求老网站webservice ResquestParams rp = new ResquestParams(); rp.MethodName = "AddInfo"; rp.Parames = hashParam; rp.URL = "http://50.73.141.111/info.asmx"; sysLog.WriteOptDisk("一路请求老网站webservice 【url】" + "http://50.73.141.111/info.asmx"); SoapWebService soapWebService = new SoapWebService(); XmlDocument xmlRes = soapWebService.RequestWebService(rp); sysLog.WriteOptDisk("老网站返回值【return】" + xmlRes); //string url = "http://"+Request.Url.Authority + "/old_website/info.asmx"; ; //byte[] bytes = Encoding.UTF8.GetBytes(strXml); //HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); //request.Method = "POST"; //request.ContentLength = bytes.Length; //request.ContentType = "text/xml"; //using (Stream requestStream = request.GetRequestStream()) //{ // requestStream.Write(bytes, 0, bytes.Length); //} //HttpWebResponse response = (HttpWebResponse)request.GetResponse(); //if (response.StatusCode != HttpStatusCode.OK) //{ // string message = String.Format("POST failed. Received HTTP {0}", // response.StatusCode); // throw new ApplicationException(message); //} //通过后台post请求各个网点客户端 return(string.Format(strResponse, "1"));; } catch (Exception ex) { sysLog.WriteOptDisk("DealXML异常【error】" + ex.Message + ex.StackTrace); return(string.Format(strResponse, "$E", ex.Message, strKey)); //return "0"; } }