Sending tables to Web Service ...

consultatech4android

Member
Licensed User
Longtime User
Hi to all.


I've got another problem, now to send requests to the Web service written in C # (. Net), using a SOAP 1.2 request. The method of the Web service can be viewed at the address below:

Service Serviço da Web

The B4A in a Code is:

B4X:
Sub Envia_Pedidos_WS As Boolean
   Dim XMLPedidos As XMLBuilder

   XMLPedidos = XMLPedidos.create("soap12:Envelope") _
                           .attribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance") _
                           .attribute("xmlns:xsd","http://www.w3.org/2001/XMLSchema") _
                           .attribute("xmlns:soap12","http://www.w3.org/2003/05/soap-envelope")

   XMLPedidos = XMLPedidos.element("soap12:Body") _
                        .element("InserePedido") _
                              .attribute("xmlns","http://aplicacaovenda.org/") _
                           .element("ds") _
                              .element("NewDataSet") _
                                 .element("xs:schema") _
                                       .attribute("id","NewDataSet") _
                                       .attribute("xmlns","") _
                                       .attribute("xmlns:xs","http://www.w3.org/2001/XMLSchema") _
                                       .attribute("xmlns:msdata","urn:schemas-microsoft-com:xml-msdata") _
                                    .element("xs:element") _
                                          .attribute("name","NewDataSet") _
                                          .attribute("msdata:IsDataSet","true") _
                                          .attribute("msdata:UseCurrentLocale","true") _
                                       .element("xs:complexType") _
                                          .element("xs:choice") _
                                                .attribute("minOccurs","0") _
                                                .attribute("maxOccurs","unbounded") _
                                             .element("xs:element") _
                                                   .attribute("name","venda") _
                                                .element("xs:complexType") _
                                                   .element("xs:sequence") _
                                                      .element("xs:element") _
                                                            .attribute("name","CodigoVenda") _
                                                            .attribute("Type","xs:int") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","DataVenda") _
                                                            .attribute("Type","xs:dateTime") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","CodigoCli") _
                                                            .attribute("Type","xs:int") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","ValorVenda") _
                                                            .attribute("Type","xs:decimal") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","Vista") _
                                                            .attribute("Type","xs:string") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","CodigoIntCli") _
                                                            .attribute("Type","xs:int") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","VendedorCli") _
                                                            .attribute("Type","xs:int") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","RotaPrincipal") _
                                                            .attribute("Type","xs:string") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","Exportado") _
                                                            .attribute("Type","xs:string") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","PalmVendor") _
                                                            .attribute("Type","xs:int") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","ObsPedido") _
                                                            .attribute("Type","xs:string") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","CondPagto") _
                                                            .attribute("Type","xs:short") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","NotaFiscal") _
                                                            .attribute("Type","xs:string") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","Carreto") _
                                                            .attribute("Type","xs:short") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","Acrescimo") _
                                                            .attribute("Type","xs:decimal") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                   .up() _
                                                .up() _
                                             .up() _
                                             .element("xs:element") _
                                                   .attribute("name","vendaitem") _
                                                .element("xs:complexType") _
                                                   .element("xs:sequence") _
                                                      .element("xs:element") _
                                                            .attribute("name","CodigoVenda") _
                                                            .attribute("Type","xs:int") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","CodigoPro") _
                                                            .attribute("Type","xs:int") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","QtdVenda") _
                                                            .attribute("Type","xs:decimal") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","UnitarioVenda") _
                                                            .attribute("Type","xs:decimal") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","FatorVenda") _
                                                            .attribute("Type","xs:string") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","CodigoIntPro") _
                                                            .attribute("Type","xs:int") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","TotalLinha") _
                                                            .attribute("Type","xs:decimal") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","PalmVendor") _
                                                            .attribute("Type","xs:int") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","Exportado") _
                                                            .attribute("Type","xs:string") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","ValorTabela") _
                                                            .attribute("Type","xs:decimal") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","NomePro") _
                                                            .attribute("Type","xs:string") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","CodigoConhecido") _
                                                            .attribute("Type","xs:string") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","Feirinha") _
                                                            .attribute("Type","xs:string") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                      .element("xs:element") _
                                                            .attribute("name","OrdemGravacao") _
                                                            .attribute("Type","xs:int") _
                                                            .attribute("minOccurs","0") _
                                                      .up() _
                                                   .up() _
                                                .up() _
                                             .up() _
                                          .up() _
                                       .up() _
                                    .up() _
                                 .up()

   Dim SQL As String
   Dim cVendas, cVendasItens As Cursor

   SQL = "SELECT * FROM venda WHERE Exportado = 'N' ORDER BY CodigoVenda"
   cVendas = Main.MobileDB.ExecQuery(SQL)
   For i = 0 To cVendas.RowCount - 1
      cVendas.Position = i
      
      XMLPedidos = XMLPedidos.element("venda") _
                           .element("CodigoVenda").text(cVendas.GetInt("CodigoVenda")).up() _
                           .element("DataVenda").text(cVendas.GetLong("DataVenda")).up() _
                           .element("CodigoCli").text(cVendas.GetInt("CodigoCli")).up() _
                           .element("ValorVenda").text(cVendas.GetDouble("ValorVenda")).up() _
                           .element("Vista").text(cVendas.GetString("Vista")).up() _
                           .element("CodigoIntCli").text(cVendas.GetInt("CodigoIntCli")).up() _
                           .element("VendedorCli").text(cVendas.GetInt("VendedorCli")).up() _
                           .element("RotaPrincipal").text(cVendas.GetString("RotaPrincipal")).up() _
                           .element("Exportado").text(cVendas.GetString("Exportado")).up() _
                           .element("PalmVendor").text(cVendas.GetInt("PalmVendor")).up() _
                           .element("ObsPedido").text(cVendas.GetString("ObsPedido")).up() _
                           .element("CondPagto").text(cVendas.GetInt("CondPagto")).up() _
                           .element("NotaFiscal").text(cVendas.GetString("NotaFiscal")).up() _
                           .element("Carreto").text(cVendas.GetInt("Carreto")).up() _
                           .element("Carreto").text(cVendas.GetInt("Acrescimo")).up().up()

   Next

   cVendas.Close
   
   SQL = "SELECT * FROM vendaitem WHERE Exportado = 'N' ORDER BY CodigoVenda,OrdemGravacao"
   cVendasItens = Main.MobileDB.ExecQuery(SQL)
   For i = 0 To cVendasItens.RowCount - 1
      cVendasItens.Position = i

      XMLPedidos = XMLPedidos.element("vendaitem") _
                           .element("CodigoVenda").text(cVendasItens.GetInt("CodigoVenda")).up() _
                           .element("CodigoPro").text(cVendasItens.GetInt("CodigoPro")).up() _
                           .element("QtdVenda").text(cVendasItens.GetDouble("QtdVenda")).up() _
                           .element("UnitarioVenda").text(cVendasItens.GetDouble("UnitarioVenda")).up() _
                           .element("FatorVenda").text(cVendasItens.GetString("FatorVenda")).up() _
                           .element("CodigoIntPro").text(cVendasItens.GetInt("CodigoIntPro")).up() _
                           .element("TotalLinha").text(cVendasItens.GetDouble("TotalLinha")).up() _
                           .element("PalmVendor").text(cVendasItens.GetInt("PalmVendor")).up() _
                           .element("Exportado").text(cVendasItens.GetString("Exportado")).up() _
                           .element("ValorTabela").text(cVendasItens.GetDouble("ValorTabela")).up() _
                           .element("NomePro").text(cVendasItens.GetString("NomePro")).up() _
                           .element("CodigoConhecido").text(cVendasItens.GetString("CodigoConhecido")).up() _
                           .element("Feirinha").text(cVendasItens.GetString("Feirinha")).up() _
                           .element("OrdemGravacao").text(cVendasItens.GetInt("OrdemGravacao")).up().up()

   Next

   cVendasItens.Close

   Dim reqVenda As HttpRequest
   Dim Endereco As String
   Dim Connect As Boolean
   Dim Para() As Byte
   Dim Inp As InputStream
   Dim conv As ByteConverter

   Para = conv.StringToBytes("<?xml version=" & Chr(34) & "1.0" & Chr(34) & " standalone=" & Chr(34) & "yes" & Chr(34) & "?>" & CRLF & XMLPedidos.asString,"UTF-8")
   Inp.InitializeFromBytesArray(Para, 0, Para.Length)   

   Endereco = Main.parametro.getWeb_Service '& "/InserePedido"

   reqVenda.InitializePost(Endereco, Inp, Para.Length)
   reqVenda.SetContentEncoding("UTF-8")
   reqVenda.SetHeader("Host", "atecnologia.no-ip.info")
   reqVenda.SetHeader("Content-Type", "text/xml; charset=utf-8")
   reqVenda.SetHeader("Content-Length", Para.Length)
   reqVenda.SetHeader("SOAPAction", "http://aplicacaovenda.org/InserePedido")
   reqVenda.Timeout = 10000 'set timeout to 10 seconds

   HttpVenda.Initialize("HttpVenda")

   If HttpVenda.Execute(reqVenda, TB_VENDA_ENV) = False Then
      Connect = False
      'Exit 'Will be false if their is already a running task (with the same id).
   End If

   Return Connect

End Sub

'#########################################################################################################
'# VENDA                                                                                                 #
'#########################################################################################################
Sub HttpVenda_ResponseError (Reason As String, StatusCode As Int, TaskId As Int)
   Dim msg As String
   Log(Reason)
   Log(StatusCode)
   ProgressDialogHide
   msg = "Erro ao conectar no Web Service." & CRLF & "Envio dos pedidos" 
   
   If Reason <> Null Then
      msg = msg & CRLF & "(" & StatusCode & ") " & Reason
   End If
   ToastMessageShow (msg, True)
End Sub

The generated XML, including SOAP 1.2 envelope and Dataset:


B4X:
<?xml version="1.0" standalone="yes"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
   <soap12:Body>
      <InserePedido xmlns="http://aplicacaovenda.org/">
         <ds>
            <NewDataSet>
               <xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
                  <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
                     <xs:complexType>
                        <xs:choice minOccurs="0" maxOccurs="unbounded">
                           <xs:element name="venda">
                              <xs:complexType>
                                 <xs:sequence>
                                    <xs:element name="CodigoVenda" Type="xs:int" minOccurs="0"/>
                                    <xs:element name="DataVenda" Type="xs:dateTime" minOccurs="0"/>
                                    <xs:element name="CodigoCli" Type="xs:int" minOccurs="0"/>
                                    <xs:element name="ValorVenda" Type="xs:decimal" minOccurs="0"/>
                                    <xs:element name="Vista" Type="xs:string" minOccurs="0"/>
                                    <xs:element name="CodigoIntCli" Type="xs:int" minOccurs="0"/>
                                    <xs:element name="VendedorCli" Type="xs:int" minOccurs="0"/>
                                    <xs:element name="RotaPrincipal" Type="xs:string" minOccurs="0"/>
                                    <xs:element name="Exportado" Type="xs:string" minOccurs="0"/>
                                    <xs:element name="PalmVendor" Type="xs:int" minOccurs="0"/>
                                    <xs:element name="ObsPedido" Type="xs:string" minOccurs="0"/>
                                    <xs:element name="CondPagto" Type="xs:short" minOccurs="0"/>
                                    <xs:element name="NotaFiscal" Type="xs:string" minOccurs="0"/>
                                    <xs:element name="Carreto" Type="xs:short" minOccurs="0"/>
                                    <xs:element name="Acrescimo" Type="xs:decimal" minOccurs="0"/>
                                 </xs:sequence>
                              </xs:complexType>
                           </xs:element>
                           <xs:element name="vendaitem">
                              <xs:complexType>
                                 <xs:sequence>
                                 <xs:element name="CodigoVenda" Type="xs:int" minOccurs="0"/>
                                    <xs:element name="CodigoPro" Type="xs:int" minOccurs="0"/>
                                    <xs:element name="QtdVenda" Type="xs:decimal" minOccurs="0"/>
                                    <xs:element name="UnitarioVenda" Type="xs:decimal" minOccurs="0"/>
                                    <xs:element name="FatorVenda" Type="xs:string" minOccurs="0"/>
                                    <xs:element name="CodigoIntPro" Type="xs:int" minOccurs="0"/>
                                    <xs:element name="TotalLinha" Type="xs:decimal" minOccurs="0"/>
                                    <xs:element name="PalmVendor" Type="xs:int" minOccurs="0"/>
                                    <xs:element name="Exportado" Type="xs:string" minOccurs="0"/>
                                    <xs:element name="ValorTabela" Type="xs:decimal" minOccurs="0"/>
                                    <xs:element name="NomePro" Type="xs:string" minOccurs="0"/>
                                    <xs:element name="CodigoConhecido" Type="xs:string" minOccurs="0"/>
                                    <xs:element name="Feirinha" Type="xs:string" minOccurs="0"/>
                                    <xs:element name="OrdemGravacao" Type="xs:int" minOccurs="0"/>
                                 </xs:sequence>
                              </xs:complexType>
                           </xs:element>
                        </xs:choice>
                     </xs:complexType>
                  </xs:element>
               </xs:schema>
                 <venda>
                  <CodigoVenda>1</CodigoVenda>
                  <DataVenda>2013-01-24T00:00:00-02:00</DataVenda>
                  <CodigoCli>191</CodigoCli>
                  <ValorVenda>0.78</ValorVenda>
                  <Vista>N</Vista>
                  <CodigoIntCli>9197</CodigoIntCli>
                  <VendedorCli>7</VendedorCli>
                  <RotaPrincipal>S</RotaPrincipal>
                  <Exportado>N</Exportado>
                  <PalmVendor>7150113</PalmVendor>
                  <ObsPedido />
                  <CondPagto>2</CondPagto>
                  <NotaFiscal>N</NotaFiscal>
                  <Carreto>1</Carreto>
                 </venda>
                 <venda>
                  <CodigoVenda>2</CodigoVenda>
                  <DataVenda>2013-01-24T00:00:00-02:00</DataVenda>
                  <CodigoCli>126</CodigoCli>
                  <ValorVenda>0.59</ValorVenda>
                  <Vista>N</Vista>
                  <CodigoIntCli>8298</CodigoIntCli>
                  <VendedorCli>7</VendedorCli>
                  <RotaPrincipal>S</RotaPrincipal>
                  <Exportado>N</Exportado>
                  <PalmVendor>7150113</PalmVendor>
                  <ObsPedido />
                  <CondPagto>2</CondPagto>
                  <NotaFiscal>N</NotaFiscal>
                  <Carreto>1</Carreto>
                 </venda>
                 <venda>
                  <CodigoVenda>3</CodigoVenda>
                  <DataVenda>2013-01-24T00:00:00-02:00</DataVenda>
                  <CodigoCli>140</CodigoCli>
                  <ValorVenda>0.76</ValorVenda>
                  <Vista>N</Vista>
                  <CodigoIntCli>8719</CodigoIntCli>
                  <VendedorCli>7</VendedorCli>
                  <RotaPrincipal>S</RotaPrincipal>
                  <Exportado>N</Exportado>
                  <PalmVendor>7150113</PalmVendor>
                  <ObsPedido />
                  <CondPagto>13</CondPagto>
                  <NotaFiscal>N</NotaFiscal>
                  <Carreto>1</Carreto>
                 </venda>
                 <vendaitem>
                  <CodigoVenda>1</CodigoVenda>
                  <CodigoPro>1</CodigoPro>
                  <QtdVenda>1.00</QtdVenda>
                  <UnitarioVenda>0.59</UnitarioVenda>
                  <FatorVenda>N</FatorVenda>
                  <CodigoIntPro>1</CodigoIntPro>
                  <TotalLinha>0.59</TotalLinha>
                  <PalmVendor>7150113</PalmVendor>
                  <Exportado>N</Exportado>
                  <ValorTabela>0.59</ValorTabela>
                  <NomePro>AGULHEIRO CESTA PT 12X1                                                                             </NomePro>
                  <CodigoConhecido>1            </CodigoConhecido>
                  <Feirinha>N</Feirinha>
                  <OrdemGravacao>1</OrdemGravacao>
                 </vendaitem>
                 <vendaitem>
                  <CodigoVenda>1</CodigoVenda>
                  <CodigoPro>2</CodigoPro>
                  <QtdVenda>1.00</QtdVenda>
                  <UnitarioVenda>0.19</UnitarioVenda>
                  <FatorVenda>N</FatorVenda>
                  <CodigoIntPro>2</CodigoIntPro>
                  <TotalLinha>0.19</TotalLinha>
                  <PalmVendor>7150113</PalmVendor>
                  <Exportado>N</Exportado>
                  <ValorTabela>0.19</ValorTabela>
                  <NomePro>AGULHA MAO CORRENTE N.01 PT 20X1                                                                    </NomePro>
                  <CodigoConhecido>2            </CodigoConhecido>
                  <Feirinha>N</Feirinha>
                  <OrdemGravacao>2</OrdemGravacao>
                 </vendaitem>
                 <vendaitem>
                  <CodigoVenda>2</CodigoVenda>
                  <CodigoPro>1</CodigoPro>
                  <QtdVenda>1.00</QtdVenda>
                  <UnitarioVenda>0.59</UnitarioVenda>
                  <FatorVenda>N</FatorVenda>
                  <CodigoIntPro>1</CodigoIntPro>
                  <TotalLinha>0.59</TotalLinha>
                  <PalmVendor>7150113</PalmVendor>
                  <Exportado>N</Exportado>
                  <ValorTabela>0.59</ValorTabela>
                  <NomePro>AGULHEIRO CESTA PT 12X1                                                                             </NomePro>
                  <CodigoConhecido>1            </CodigoConhecido>
                  <Feirinha>N</Feirinha>
                  <OrdemGravacao>1</OrdemGravacao>
                 </vendaitem>
                 <vendaitem>
                  <CodigoVenda>3</CodigoVenda>
                  <CodigoPro>2</CodigoPro>
                  <QtdVenda>4.00</QtdVenda>
                  <UnitarioVenda>0.19</UnitarioVenda>
                  <FatorVenda>N</FatorVenda>
                  <CodigoIntPro>2</CodigoIntPro>
                  <TotalLinha>0.76</TotalLinha>
                  <PalmVendor>7150113</PalmVendor>
                  <Exportado>N</Exportado>
                  <ValorTabela>0.76</ValorTabela>
                  <NomePro>AGULHA MAO CORRENTE N.01 PT 20X1                                                                    </NomePro>
                  <CodigoConhecido>2            </CodigoConhecido>
                  <Feirinha>N</Feirinha>
                  <OrdemGravacao>1</OrdemGravacao>
                 </vendaitem>
            </NewDataSet>
         </ds>
      </InserePedido>
   </soap12:Body>
</soap12:Envelope>


In the event HttpVenda_ResponseError:

Reason = org.apache.http.client.ClientProrocol.Exception
StatusCode = -1


What can this be?
Does anyone have an idea what might be happening?
:BangHead:
 
Top