本文介绍了阅读已签名的回复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我发送数据时从Web服务获得响应;我收到了以下回复: < SOAP-ENV:Envelope xmlns:SOAP-ENV = http://schemas.xmlsoap.org/soap/envelope/ > < SOAP-ENV:标题 > < wsse:Security xmlns:wsse = http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd xmlns:wsu = http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd SOAP-ENV:mustUnderstand = 1 > < ds:签名 xmlns:ds = http://www.w3.org/2000/09/xmldsig# Id = SIG-478012 > < ds :SignedInfo > < ds:CanonicalizationMethod 算法 = http://www.w3.org/2001/10/xml-exc-c14n# > < ec:InclusiveNamespaces xmlns:ec = http://www.w3.org/2001/10/xml-exc-c14n#\" PrefixList = SOAP-ENV / > < / ds:CanonicalizationMethod > < ds:SignatureMethod 算法 = http://www.w3.org/2000/09/xmldsig#rsa-sha1 / > < ds:参考 URI = #id-478011 > < ds:转换 > < ds:转换 算法 = http://www.w3.org/2001/10/xml-exc-c14n# > < ec:InclusiveNamespaces xmlns:ec = http:// www。 w3.org/2001/10/xml-exc-c14n#\" PrefixList = / > < / ds:转换 > < / ds:转换 > < ds:DigestMethod 算法 = http://www.w3.org/2000/09/xmldsig#sha1 / > < ds: DigestValue > gPOXTVuXDw2ktXu3Fiyjoz35JwY = < / ds:DigestValue > < / ds:参考 > < / ds:SignedInfo > < ds:SignatureValue > e7AOmryll5EXw3euAOlO2CwL + N3wpR + QHz8Zmlz + hBFZ7kmQ9QXkupO + MUkDrnHu / MsOZr7Q0j60heMbM4u3yIiTRPE0HsEOV1BQ / + v0LX + XSGo1EiHlcYbEo8Yn + aHFmR4z81TV8TycRXMBUoyJXl2Y / yLjFPH8TptpKLagEOYgcJQ340Cw7rVBfG + tuVwU388F / MDIV / vRhIjpHViSHSP8C7xO5NZvNoGsg5f66ATzkwkB4wmeAmHud3Mbuj7Vdq3Sw == < / ds:SignatureValue > < ds:KeyInfo Id = KI-0ACB9EF7167DC955151536323314584358508 > < wsse:SecurityTokenReference wsu:Id = STR -0ACB9EF7167DC955151536323314584358509 > < ds:X509Data > < ds:X509IssuerSerial > < ds:X509IssuerName > CN = AC SUB CERTICAMARA,O = CERTICAMARA SA,OU = NIT 830084433-7, C = CO,ST = DISTRITO CAPITAL,L = BOGOTA,STREET = www.certicamara.com < / ds:X509IssuerName > < ds:X509SerialNumber > 91436926122049919406185072624124 < / ds:X509SerialNumber > < / ds:X509IssuerSerial > < / ds:X509Data > < / wsse:SecurityTokenReference > < / ds:KeyInfo > < / ds:签名 > < wsu:时间戳 wsu:Id = TS-478010 > < wsu:已创建 > 2018- 09-07T12:28:34.584Z < / wsu:已创建 > < wsu:Expires > 2018-09-07T12:33:34.584Z < / wsu:到期 > < / wsu:时间戳 > < wsse11:SignatureConfirmation xmlns:wsse11 = http://docs.oasis-open.org/wss/oasis -wss-wssecurity-secext-1.1.xsd wsu:Id = SC-478009 / > < / wsse:Security > < / SOAP-ENV:标题 > < SOAP-ENV:正文 xmlns:wsu = http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd wsu:Id = id-478011 > < ns2:EnvioFacturaElectronicaRespuesta xmlns:ns2 = http://www.lodeg.gov.co/services/felectronica/ReportarFactura xmlns:ns3 = http://www.lodeg.gov.co/services/felectronica/ConsultaDocumentos xmlns:ns4 = http://www.lodeg.gov.co/services/felectronica/VersionDespliegue > < ns2:版本 > ; Componente lodeg < / ns2:Version > < ns2:ReceivedDateTime > 2018-09-07T07:28:34.392-05:00 < / ns2:ReceivedDateTime > < ns2:ResponseDateTime > 2018-09-07T07:28:34.583-05:00 < ; / ns2:ResponseDateTime > < ns2:响应 > 200 < / ns2:响应 > < ns2 :评论 > Ejemplar recibidoexitosamentepasaráaveificación。< / ns2:评论 > < / ns2:EnvioFacturaElectronicaRespuesta > < / SOAP-ENV:正文 > < / SOAP-ENV:Envelope > 似乎dot net需要资源ponse没有签名。 我尝试过: 是不是优雅的解决方案,允许继续接收响应及其相应过程的过程。我不得不使用CustomEncoder,以便在它到达之前处理响应以消除整个签名。基于这个博客https://blogs.msdn.microsoft.com/dsnotes/2016/03/08/wcf-custom-encoder-to-read-mtom-response/ public override 消息ReadMessage(ArraySegment< byte> buffer ,BufferManager bufferManager, string contentType) { // 将接收到的缓冲区转换为字符串 byte [] incomingResponse = buffer.Array; incomingResponse = RemoveSignatures(incomingResponse); ........ 和方法...... private byte [] RemoveSignatures( byte [] stream) { string stream2 = Encoding.UTF8.GetString(stream); stream2 = stream2.Replace( \0, ); 正则表达式x = 新正则表达式( (\\< SOAP-ENV:Header\\>)(\\< / SOAP-ENV:Header\\>)(*?)); string repl = ; stream2 = x.Replace(stream2, $ 1 + repl + $ 3); byte [] streamNuevo = Encoding.ASCII.GetBytes(stream2); return streamNuevo; } 这条线是我收到签名回复的地方: AcuseRecibo acuseRecibo = new AcuseRecibo(); acuseRecibo = Service.EnvioFacturaElectronica(envioFacturaElectronicaPeticion.EnvioFacturaElectronicaPeticion1); return acuseRecibo.Comments.ToString(); 问题,实现ReadMessage方法??? 解决方案 1 + repl + 3); byte [] streamNuevo = Encoding.ASCII.GetBytes(stream2); return streamNuevo; } 这条线是我收到签名回复的地方: AcuseRecibo acuseRecibo = new AcuseRecibo(); acuseRecibo = Service.EnvioFacturaElectronica(envioFacturaElectronicaPeticion.EnvioFacturaElectronicaPeticion1); 返回 acuseRecibo.Comments.ToString(); 问题,实现ReadMessage M的地方ethod ??? I get the response from a web service when I send data; I've received the following response:<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" SOAP-ENV:mustUnderstand="1"><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="SIG-478012"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="SOAP-ENV"/></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI="#id-478011"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList=""/></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>gPOXTVuXDw2ktXu3Fiyjoz35JwY=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>e7AOmryll5EXw3euAOlO2CwL+N3wpR+QHz8Zmlz+hBFZ7kmQ9QXkupO+MUkDrnHu/MsOZr7Q0j60heMbM4u3yIiTRPE0HsEOV1BQ/+v0LX+XSGo1EiHlcYbEo8Yn+aHFmR4z81TV8TycRXMBUoyJXl2Y/yLjFPH8TptpKLagEOYgcJQ340Cw7rVBfG+tuVwU388F/MDiv/vRhIjpHViSHSP8C7xO5NZvNoGsg5f66ATzkwkB4wmeAmHud3Mbuj7Vdq3Sw==</ds:SignatureValue><ds:KeyInfo Id="KI-0ACB9EF7167DC955151536323314584358508"><wsse:SecurityTokenReference wsu:Id="STR-0ACB9EF7167DC955151536323314584358509"><ds:X509Data><ds:X509IssuerSerial><ds:X509IssuerName>CN=AC SUB CERTICAMARA,O=CERTICAMARA S.A,OU=NIT 830084433-7,C=CO,ST=DISTRITO CAPITAL,L=BOGOTA,STREET=www.certicamara.com</ds:X509IssuerName><ds:X509SerialNumber>91436926122049919406185072624124</ds:X509SerialNumber></ds:X509IssuerSerial></ds:X509Data></wsse:SecurityTokenReference></ds:KeyInfo></ds:Signature><wsu:Timestamp wsu:Id="TS-478010"><wsu:Created>2018-09-07T12:28:34.584Z</wsu:Created><wsu:Expires>2018-09-07T12:33:34.584Z</wsu:Expires></wsu:Timestamp><wsse11:SignatureConfirmation xmlns:wsse11="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd" wsu:Id="SC-478009"/></wsse:Security></SOAP-ENV:Header><SOAP-ENV:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-478011"><ns2:EnvioFacturaElectronicaRespuesta xmlns:ns2="http://www.lodeg.gov.co/services/felectronica/ReportarFactura" xmlns:ns3="http://www.lodeg.gov.co/services/felectronica/ConsultaDocumentos" xmlns:ns4="http://www.lodeg.gov.co/services/felectronica/VersionDespliegue"><ns2:Version>Componente lodeg</ns2:Version><ns2:ReceivedDateTime>2018-09-07T07:28:34.392-05:00</ns2:ReceivedDateTime><ns2:ResponseDateTime>2018-09-07T07:28:34.583-05:00</ns2:ResponseDateTime><ns2:Response>200</ns2:Response><ns2:Comments>Ejemplar recibido exitosamente pasará a verificación.</ns2:Comments></ns2:EnvioFacturaElectronicaRespuesta></SOAP-ENV:Body></SOAP-ENV:Envelope>It seems that dot net expects a response without a signature.What I have tried:Is Not an Elegant solution, allows to continue with the process of reception of the response and its corresponding process. I had to use a CustomEncoder, in order to process the response before it arrived to eliminate the entire signature. Base on this blog https://blogs.msdn.microsoft.com/dsnotes/2016/03/08/wcf-custom-encoder-to-read-mtom-response/public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType) { //Convert the received buffer into a string byte[] incomingResponse = buffer.Array; incomingResponse = RemoveSignatures(incomingResponse); ........and a method...private byte[] RemoveSignatures(byte[] stream) { string stream2 = Encoding.UTF8.GetString(stream); stream2 = stream2.Replace("\0", ""); Regex x = new Regex("(\\<SOAP-ENV:Header\\>)(.*?)(\\</SOAP-ENV:Header\\>)"); string repl = ""; stream2 = x.Replace(stream2, "$1" + repl + "$3"); byte[] streamNuevo = Encoding.ASCII.GetBytes(stream2); return streamNuevo; }this lines are where I recived the signed Response:AcuseRecibo acuseRecibo = new AcuseRecibo(); acuseRecibo = Service.EnvioFacturaElectronica(envioFacturaElectronicaPeticion.EnvioFacturaElectronicaPeticion1); return acuseRecibo.Comments.ToString();The question, where implement ReadMessage Method??? 解决方案 1" + repl + "3"); byte[] streamNuevo = Encoding.ASCII.GetBytes(stream2); return streamNuevo; }this lines are where I recived the signed Response:AcuseRecibo acuseRecibo = new AcuseRecibo(); acuseRecibo = Service.EnvioFacturaElectronica(envioFacturaElectronicaPeticion.EnvioFacturaElectronicaPeticion1); return acuseRecibo.Comments.ToString();The question, where implement ReadMessage Method??? 这篇关于阅读已签名的回复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-27 00:44
查看更多