1+ // ***********************************************************************
2+ // Assembly : OpenAC.Net.NFSe
3+ // Author : Felipe Silveira/Transis
4+ // Created : 02-13-2023
5+ //
6+ // ***********************************************************************
7+ // <copyright file="Pronim2ServiceClient.cs" company="OpenAC .Net">
8+ // The MIT License (MIT)
9+ // Copyright (c) 2014 - 2024 Projeto OpenAC .Net
10+ //
11+ // Permission is hereby granted, free of charge, to any person obtaining
12+ // a copy of this software and associated documentation files (the "Software"),
13+ // to deal in the Software without restriction, including without limitation
14+ // the rights to use, copy, modify, merge, publish, distribute, sublicense,
15+ // and/or sell copies of the Software, and to permit persons to whom the
16+ // Software is furnished to do so, subject to the following conditions:
17+ // The above copyright notice and this permission notice shall be
18+ // included in all copies or substantial portions of the Software.
19+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22+ // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
23+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24+ // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25+ // DEALINGS IN THE SOFTWARE.
26+ // </copyright>
27+ // <summary></summary>
28+ // ***********************************************************************
29+
30+ using System ;
31+ using System . Security . Cryptography . X509Certificates ;
32+ using System . Text ;
33+ using System . Xml . Linq ;
34+ using OpenAC . Net . Core . Extensions ;
35+ using OpenAC . Net . DFe . Core ;
36+ using OpenAC . Net . NFSe . Commom ;
37+ using OpenAC . Net . NFSe . Commom . Client ;
38+ using OpenAC . Net . NFSe . Commom . Interface ;
39+ using OpenAC . Net . NFSe . Commom . Types ;
40+
41+ namespace OpenAC . Net . NFSe . Providers ;
42+
43+ internal sealed class DSF203ServiceClient : NFSeSoapServiceClient , IServiceClient
44+ {
45+ #region Constructors
46+
47+ public DSF203ServiceClient ( ProviderDSF203 provider , TipoUrl tipoUrl , X509Certificate2 certificado ) : base ( provider , tipoUrl , certificado , SoapVersion . Soap11 )
48+ {
49+ }
50+
51+ public DSF203ServiceClient ( ProviderDSF203 provider , TipoUrl tipoUrl ) : base ( provider , tipoUrl , SoapVersion . Soap11 )
52+ {
53+ }
54+
55+ #endregion Constructors
56+
57+ #region Methods
58+
59+ public string Enviar ( string cabec , string msg )
60+ {
61+ var message = new StringBuilder ( ) ;
62+ message . Append ( "<nfse:RecepcionarLoteRps>" ) ;
63+ message . Append ( msg ) ;
64+ message . Append ( "</nfse:RecepcionarLoteRps>" ) ;
65+ return Execute ( message . ToString ( ) , "RecepcionarLoteRpsResponse" ) ;
66+ }
67+
68+ public string EnviarSincrono ( string cabec , string msg )
69+ {
70+ var message = new StringBuilder ( ) ;
71+ message . Append ( "<nfse:RecepcionarLoteRpsSincrono>" ) ;
72+ message . Append ( msg ) ;
73+ message . Append ( "</nfse:RecepcionarLoteRpsSincrono>" ) ;
74+ return Execute ( message . ToString ( ) , "RecepcionarLoteRpsSincronoResponse" ) ;
75+ }
76+
77+ public string CancelarNFSe ( string cabec , string msg )
78+ {
79+ var message = new StringBuilder ( ) ;
80+ message . Append ( "<nfse:CancelarNfse>" ) ;
81+ message . Append ( msg ) ;
82+ message . Append ( "</nfse:CancelarNfse>" ) ;
83+ return Execute ( message . ToString ( ) , "CancelarNfseResponse" ) ;
84+ }
85+
86+ public string CancelarNFSeLote ( string cabec , string msg )
87+ {
88+ throw new NotImplementedException ( ) ;
89+ }
90+
91+ public string ConsultarLoteRps ( string cabec , string msg )
92+ {
93+ var message = new StringBuilder ( ) ;
94+ message . Append ( "<nfse:ConsultarLoteRps>" ) ;
95+ message . Append ( msg ) ;
96+ message . Append ( "</nfse:ConsultarLoteRps>" ) ;
97+ return Execute ( message . ToString ( ) , "ConsultarLoteRpsResponse" ) ;
98+ }
99+
100+ public string ConsultarNFSe ( string cabec , string msg )
101+ {
102+ var message = new StringBuilder ( ) ;
103+ message . Append ( "<nfse:ConsultarNfseServicoPrestado>" ) ;
104+ message . Append ( msg ) ;
105+ message . Append ( "</nfse:ConsultarNfseServicoPrestado>" ) ;
106+ return Execute ( message . ToString ( ) , "ConsultarNfseServicoPrestadoResponse" ) ;
107+ }
108+
109+ public string ConsultarNFSeRps ( string cabec , string msg )
110+ {
111+ var message = new StringBuilder ( ) ;
112+ message . Append ( "<nfse:ConsultarNfsePorRps>" ) ;
113+ message . Append ( msg ) ;
114+ message . Append ( "</nfse:ConsultarNfsePorRps>" ) ;
115+ return Execute ( message . ToString ( ) , "ConsultarNfsePorRpsResponse" ) ;
116+ }
117+
118+ public string ConsultarSequencialRps ( string cabec , string msg )
119+ {
120+ throw new NotImplementedException ( ) ;
121+ }
122+
123+ public string ConsultarSituacao ( string cabec , string msg )
124+ {
125+ throw new NotImplementedException ( ) ;
126+ }
127+
128+ public string SubstituirNFSe ( string cabec , string msg )
129+ {
130+ var message = new StringBuilder ( ) ;
131+ message . Append ( "<nfse:SubstituirNfse>" ) ;
132+ message . Append ( msg ) ;
133+ message . Append ( "</nfse:SubstituirNfse>" ) ;
134+ return Execute ( message . ToString ( ) , "SubstituirNfseResponse" ) ;
135+ }
136+
137+ protected override string TratarRetorno ( XElement xmlDocument , string [ ] responseTag )
138+ {
139+ var element = xmlDocument . ElementAnyNs ( "Fault" ) ;
140+ if ( element != null )
141+ {
142+ var exMessage =
143+ $ "{ element . ElementAnyNs ( "faultcode" ) . GetValue < string > ( ) } - { element . ElementAnyNs ( "faultstring" ) . GetValue < string > ( ) } ";
144+ throw new OpenDFeCommunicationException ( exMessage ) ;
145+ }
146+
147+ return xmlDocument . ElementAnyNs ( responseTag [ 0 ] ) . ToString ( ) ;
148+ }
149+
150+ private string Execute ( string message , string responseTag ) =>
151+ Execute ( "" , message , "" , [ responseTag ] , [ "xmlns:nfse=\" http://nfse.abrasf.org.br\" " ] ) ;
152+
153+ #endregion Methods
154+ }
0 commit comments