WEB SERVICES

USUARIO.EXCLUIDOS 21/12/2006 04:00:18
#191334
estou tentando carregar o banco de dados com o resultado de um web service, esta retornando esse erro, não consigo resolve-lo!!!

System.Net.WebException was unhandled
Message="WebException"
StackTrace:
em System.Web.Services.Protocols.SoapHttpClientProtocol.doInvoke()
em System.Web.Services.Protocols.SoapHttpClientProtocol.doAsyncInvoke()
at WorkItem.doWork()
em System.Threading.Timer.ring()


Aqui está o código que estou usando!

Public Class FormAtualiza
Dim representantes() As Representantes
Dim prodcat() As ProdCat
Dim clientes() As Clientes
Dim operacao1Concluida, operacao2Concluida, operacao3Concluida As Boolean
Dim insercao1Concluida, insercao2Concluida, insercao3Concluida As Boolean

[c] Public Sub RepresentantesCallback(ByVal ar As IAsyncResult)
Cursor.Current = Cursors.WaitCursor
Try
Dim server As serverwsRepresentantes = CType(ar.AsyncState, serverwsRepresentantes)
representantes = server.EndlistarRepresentantes(ar)
Catch ex As Web.Services.Protocols.SoapException
MsgBox(ex)
Try
Dim server As serverwsRepresentantes = CType(ar.AsyncState, serverwsRepresentantes)
representantes = server.EndlistarRepresentantes(ar)
Catch x As Exception
MsgBox(x)
End Try
End Try
operacao1Concluida = True
Cursor.Current = Cursors.Default
AtualizaDados()
End Sub


    Public Sub listaProdCatCallback(ByVal ar As IAsyncResult)
Cursor.Current = Cursors.WaitCursor
Try
Dim server As serverwsRepresentantes = CType(ar.AsyncState, serverwsRepresentantes)
prodcat = server.EndlistaProdCat(ar)
Catch ex As System.Web.Services.Protocols.SoapException
MsgBox(ex)
Try
Dim server As serverwsRepresentantes = CType(ar.AsyncState, serverwsRepresentantes)
prodcat = server.EndlistaProdCat(ar)
Catch x As System.Web.Services.Protocols.SoapException
MsgBox(x)
End Try
End Try
operacao2Concluida = True
Cursor.Current = Cursors.Default
AtualizaDados()
End Sub


    Public Sub listaClientesCallback(ByVal ar As IAsyncResult)
Cursor.Current = Cursors.WaitCursor
Try
Dim server As serverwsRepresentantes = CType(ar.AsyncState, serverwsRepresentantes)
clientes = server.EndlistarClientes(ar)
Catch ex As Web.Services.Protocols.SoapException
MsgBox(ex)
Try
Dim server As serverwsRepresentantes = CType(ar.AsyncState, serverwsRepresentantes)
clientes = server.EndlistarClientes(ar)
Catch x As Web.Services.Protocols.SoapException
MsgBox(x)
End Try
End Try
operacao3Concluida = True
Cursor.Current = Cursors.Default
AtualizaDados()
End Sub



    Private Sub AtualizaDados()

Dim representantesLength, prodcatLength, i As Integer

Dim connection As Data.SqlServerCe.SqlCeConnection = New Data.SqlServerCe.SqlCeConnection("DataSource = \AFV\BdAFV\SoccolBd.sdf;")
Dim command As SqlCeCommand = connection.CreateCommand()
connection.Open()

If Not representantes Is Nothing Then representantesLength = representantes.Length
If Not prodcat Is Nothing Then prodcatLength = prodcat.Length

If Not (operacao1Concluida And operacao2Concluida And operacao3Concluida) Then Exit Sub

If Not (insercao1Concluida) Then

command.CommandText = "DELETE FROM wsProdCat;"
command.Parameters.Clear()
command.ExecuteNonQuery()

i = 0
For Each listaProdCat As ProdCat In prodcat
command.CommandText = "INSERT INTO wsProdCat ( Cod, Nome) VALUES ( ?, ? )"
command.Parameters.Clear()
command.Parameters.Add("@codigo", listaProdCat.codigo)
command.Parameters.Add("@nome", listaProdCat.nome)
command.ExecuteNonQuery()
i += 1
Next
MsgBox(" Recebidas " & i & " Categorias de Produtos")
insercao1Concluida = True
End If

If Not (insercao2Concluida) Then
i = 0
command.CommandText = "DELETE FROM wsRepresentante;"
command.Parameters.Clear()
command.ExecuteNonQuery()
For Each representante As Representantes In representantes
command.CommandText = "INSERT INTO wsRepresentante ( Cod, Nome, NmReduzido, Endereco, Bairro, Uf, Cep, Cpf, Fax, Fone, Email, Login, Senha ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"
command.Parameters.Clear()
command.Parameters.Add("@codigo", representante.codigo)
command.Parameters.Add("@nome", representante.nome)
command.Parameters.Add("@nmReduz", representante.nmReduz)
command.Parameters.Add("@endereco", representante.endereco)
command.Parameters.Add("@bairro", representante.bairro)
command.Parameters.Add("@estado", representante.estado)
command.Parameters.Add("@cep", representante.cep)
command.Parameters.Add("@cgc", representante.cgc)
command.Parameters.Add("@fax", representante.fax)
command.Parameters.Add("@fone", representante.telefone)
command.Parameters.Add("@email", representante.email)
command.Parameters.Add("@login", representante.login)
command.Parameters.Add("@senha", representante.senha)
command.ExecuteNonQuery()
i += 1
Next
MsgBox(" Recebidas as informacoes de " & i & " Revendedores")
insercao2Concluida = True
End If


If Not (insercao3Concluida) Then
command.CommandText = "DELETE FROM wsClientes;"
command.Parameters.Clear()
command.ExecuteNonQuery()
i = 0
For Each dtCliente As Clientes In clientes
command.CommandText = "INSERT INTO wsClientes ( Nome, NmReduzido, Representante, Endereco, Uf, Cep, Cnpj, Tel) "
command.CommandText += " VALUES ( ?, ?, ?, ?, ?, ?, ?, ?)"
command.Parameters.Clear()
command.Parameters.Add("@nome", dtCliente.nome)
command.Parameters.Add("@nmReduz", dtCliente.nmReduz)
command.Parameters.Add("@representante", "V00017")
command.Parameters.Add("@endereco", dtCliente.endereco)
command.Parameters.Add("@estado", dtCliente.estado)
command.Parameters.Add("@cep", dtCliente.cep)
command.Parameters.Add("@cgc", dtCliente.cgc)
command.Parameters.Add("@fone", dtCliente.telefone)
command.ExecuteNonQuery()
i += 1
Next
MsgBox(" Recebidas as informacoes de " & i & " Revendedores")
insercao3Concluida = True
End If
connection.Close()
Cursor.Current = Cursors.Default
MsgBox(" Ok! Sincronização Finalizda com Sucesso!!")
' Exit Sub
End Sub


    Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
Me.Close()
End Sub


    Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
Form2.Show()
End Sub


    Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
txBWs.Text = "Iniciando Sincronização de Bancos de Dados com a Empresa..."
Button1.Enabled = False

AtualizaDados()

Dim server As New serverwsRepresentantes


Dim callback As AsyncCallback = New AsyncCallback(AddressOf RepresentantesCallback)
server.BeginlistarRepresentantes(callback, server)

Dim callback2 As AsyncCallback = New AsyncCallback(AddressOf listaProdCatCallback)
server.BeginlistaProdCat(callback2, server)

Dim callback3 As AsyncCallback = New AsyncCallback(AddressOf listaClientesCallback)
server.BeginlistarClientes("V00017", callback3, server)

End Sub

USUARIO.EXCLUIDOS 21/12/2006 18:13:15
#191594
Olá pessoal, fiz uma nova tentativa como segue abaixo, pensando ser um problema de THREADS, bom, que seja então um botão para cada atualização de bancos de dados (são 7) e, surpresa, o mesmo erro, no mesmo lugar, reference.vb, endInvoke

'''<remarks/>
        Public Function EndlistarClientes(ByVal asyncResult As System.IAsyncResult) As Clientes()
Dim results() As Object = Me.EndInvoke(asyncResult)
Return CType(results(0),Clientes())
End Function


O estranho é que agora eu clico no botão, ele abre a primeira requisição, teoricamente teria que fechar ela, finaliza o trabalho de inserção e, no segundo botão, quando ele chama o endInvoke da segunda requisição, ocorre o mesmo problema que citei no post anterior, sempre no segundo, vejam meu código...

Imports System.Data
Imports System.Data.SqlServerCe
Imports System.Web.Services
Imports System.Data.DataTable
Imports System.Windows.Forms
Imports AFVScb.br.com.soccolbarbieri.www

Public Class formAtualizaMultiplosBotoes
Dim representantes() As Representantes
Dim prodcat() As ProdCat
Dim subprodcat() As SubProdCat
Dim clientes() As Clientes
Dim i As Integer
Dim operacao1Concluida, operacao2Concluida, operacao3Concluida, operacao4Concluida As Boolean
Dim insercao1Concluida, insercao2Concluida, insercao3Concluida, insercao4Concluida As Boolean

[c] Private Sub btnAtClientes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAtClientes.Click
Cursor.Current = Cursors.WaitCursor
btnAtClientes.Enabled = False
Dim server As New serverwsRepresentantes
Dim meuResultado As IAsyncResult
Dim connection As Data.SqlServerCe.SqlCeConnection = New Data.SqlServerCe.SqlCeConnection("DataSource = \AFV\BdAFV\SoccolBd.sdf;")
Dim command As SqlCeCommand = connection.CreateCommand()
connection.Open()

meuResultado = server.BeginlistarClientes("V00017", Nothing, server)

clientes = server.EndlistarClientes(meuResultado)

command.CommandText = "DELETE FROM wsClientes;"
command.Parameters.Clear()
command.ExecuteNonQuery()
i = 0

For Each dtCliente As Clientes In clientes
command.CommandText = "INSERT INTO wsClientes ( Nome, NmReduzido, Representante, Endereco, Uf, Cep, Cnpj, Tel) "
command.CommandText += " VALUES ( ?, ?, ?, ?, ?, ?, ?, ?)"
command.Parameters.Clear()
command.Parameters.Add("@nome", dtCliente.nome)
command.Parameters.Add("@nmReduz", dtCliente.nmReduz)
command.Parameters.Add("@representante", "V00017")
command.Parameters.Add("@endereco", dtCliente.endereco)
command.Parameters.Add("@estado", dtCliente.estado)
command.Parameters.Add("@cep", dtCliente.cep)
command.Parameters.Add("@cgc", dtCliente.cgc)
command.Parameters.Add("@fone", dtCliente.telefone)
command.ExecuteNonQuery()
i += 1
Next
Cursor.Current = Cursors.Default
MsgBox("Atualização Finalizada, recebidos dados de " & i & " Clientes")
btnAtClientes.Enabled = True
End Sub


    Private Sub btnAtCatProd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAtCatProd.Click
Cursor.Current = Cursors.WaitCursor
btnAtClientes.Enabled = False
Dim server As New serverwsRepresentantes
Dim meuResultado As IAsyncResult
Dim connection As Data.SqlServerCe.SqlCeConnection = New Data.SqlServerCe.SqlCeConnection("DataSource = \AFV\BdAFV\SoccolBd.sdf;")
Dim command As SqlCeCommand = connection.CreateCommand()
connection.Open()

meuResultado = server.BeginlistaProdCat(Nothing, server)

prodcat = server.EndlistaProdCat(meuResultado)

command.CommandText = "DELETE FROM wsProdCat;"
command.Parameters.Clear()
command.ExecuteNonQuery()

i = 0
For Each listaProdCat As ProdCat In prodcat
command.CommandText = "INSERT INTO wsProdCat ( Cod, Nome) VALUES ( ?, ? )"
command.Parameters.Clear()
command.Parameters.Add("@codigo", listaProdCat.codigo)
command.Parameters.Add("@nome", listaProdCat.nome)
command.ExecuteNonQuery()
i += 1
Next
Cursor.Current = Cursors.Default
MsgBox("Atualização Finalizada, recebidos dados de " & i & " Categorias de Produtos")
btnAtClientes.Enabled = True


End Sub

End Class

a dúvida agora é, algum dos amigos conhece alguma maneira para fechar, limpar, excluir da memória, eliminar de qualquer forma essa primeira ASYNCREQUEST assim que ela terminar ou ao menos quando chamar o segundo botão??
Tópico encerrado , respostas não são mais permitidas