AMB Posted May 7, 2012 at 08:49 AM Report #453485 Posted May 7, 2012 at 08:49 AM Bom dia è o seguinte eu tenho uma gridview com hyperlink ----> werservice1.asmx?id=1234 eu queria agora é que dentro do wersevice colocasse o id numa variavel em que ficava tipo x=1234. Já tentei com x = Request.QueryString["id"] mas dá erros: Error 13 Identifier expected. C:\Documents and Settings\teste\Os meus documentos\Visual Studio 2008\Projects\WebApplication3\WebApplication3\WebService1.asmx.vb Error 12 Name 'Request' is not declared. C:\Documents and Settings\teste\Os meus documentos\Visual Studio 2008\Projects\WebApplication3\WebApplication3\WebService1.asmx.vb
Caça Posted May 7, 2012 at 10:15 PM Report #453665 Posted May 7, 2012 at 10:15 PM Qual é o objectivo? Pedro Martins Não respondo a duvidas por PM
AMB Posted May 8, 2012 at 08:15 AM Author Report #453694 Posted May 8, 2012 at 08:15 AM É o seguinte eu tenho um hyperlink numa gridview para apanhar o id correspondente à linha e depois quero apartir desse hyperlink chamar o webservice para ele executar umas querys à base dados...mas para isso preciso do id para completar as querys.... já coloquei HttpContext.Current.Request.QueryString("id") mas o id vem vazio.... Desde já obrigado
Caça Posted May 8, 2012 at 08:23 AM Report #453697 Posted May 8, 2012 at 08:23 AM Que tipo de serviço estás a usar? Pedro Martins Não respondo a duvidas por PM
AMB Posted May 8, 2012 at 08:29 AM Author Report #453698 Posted May 8, 2012 at 08:29 AM Desculpa mas não entendi a tua questão.... Eu criei um web service nao visual studio e pretendo que ao clicar no link que o web service verifique se existe informação em anexos referente ao id em questão. Caso sim mostra o pdf caso não vai actualizar a base dados indo a uma outra bd buscar a informação em falta....
Caça Posted May 8, 2012 at 08:32 AM Report #453699 Posted May 8, 2012 at 08:32 AM Qual é a extensão? Para o que pretendes tem de ser um asmx e para ires buscar o valor tens de indicar o caminho completo Context.Request.QueryString("ID") Pedro Martins Não respondo a duvidas por PM
AMB Posted May 8, 2012 at 08:37 AM Author Report #453700 Posted May 8, 2012 at 08:37 AM a Minha url depois de clicar no link fica http://localhost:3072/WebService1.asmx?id=492430 Só que acho que o problema de depois ele apresentar um id vazio é que no link acima aparece a pagina do webservice com o nome que dei a (<WebMethod()> _ Public Function nleitura() As String) nleitura em jeito de link e quando clico fica o hyperlink http://localhost:3072/WebService1.asmx?op=nleitura Depois clico no invoke (localhost:3072/WebService1.asmx/nleitura) e ai aparece o id vazio.... Acho que o problema é por aqui, aparecerem estas paginas pelo meio, mas também não sei como as retirar....
Caça Posted May 8, 2012 at 09:11 AM Report #453702 Posted May 8, 2012 at 09:11 AM Vê isto http://stackoverflow.com/questions/2006828/possible-to-invoke-asmx-service-with-parameter-via-url-query-string Pedro Martins Não respondo a duvidas por PM
AMB Posted May 8, 2012 at 09:37 AM Author Report #453708 Posted May 8, 2012 at 09:37 AM Eu já coloquei como httpget, mas o id continua a aparecer vazio na altura de execução da query! Quanto à outra questão de gerar um cliente proxy na página da grid, não sei como fazê-lo.... :bored:
Caça Posted May 8, 2012 at 09:56 AM Report #453712 Posted May 8, 2012 at 09:56 AM Agora não vais utilizar o QueryString, mas sim um parâmetro, altera a tua função para Public Function nleitura(ByVal ID as Integer) As String e em vez de ires buscar o valor do ID ao QueryString, vais buscar a variável ID Pedro Martins Não respondo a duvidas por PM
AMB Posted May 8, 2012 at 10:21 AM Author Report #453721 Posted May 8, 2012 at 10:21 AM Tenho o seguinte código agora: <WebMethod()> _ <ScriptMethod(UseHttpGet:=True)> _ <ScriptMethod(UseHttpPost:=True)> _ 'Public Function nleitura() As String Public Function nleitura(ByVal id As Integer) As String Dim conne As String 'Dim x As String 'x = HttpContext.Current.Request.QueryString("id") 'x = Context.Request.QueryString("id") Dim nleitura1 As String Dim nleiturat As String conne = "Data Source=localhost;Initial Catalog=DC;Integrated Security=True" Dim conn As New SqlConnection Dim comand As New SqlCommand conn.ConnectionString = conne conn.Open() comand.Connection = conn comand.CommandText = "SELECT ident FROM ps WHERE (ident = '" & id & "')" nleitura = comand.ExecuteScalar Mas continua sem funcionar está alguma coisa errada???
Caça Posted May 8, 2012 at 10:25 AM Report #453723 Posted May 8, 2012 at 10:25 AM Está a dar erro? Que link estás a utilizar para a chamar? Deves trocar esta linha nleitura = comand.ExecuteScalar por esta Return comand.ExecuteScalar Pedro Martins Não respondo a duvidas por PM
AMB Posted May 8, 2012 at 10:29 AM Author Report #453726 Posted May 8, 2012 at 10:29 AM Eu logo a seguir ao trecho de código que coloquei tenho If nleitura Is Nothing OrElse IsDBNull(nleitura) Then Return "Erro nº processo '" & id & "'" Else .... E aparece assim quando clico no invoke : <string>Erro nº processo ''</string>
Caça Posted May 8, 2012 at 10:37 AM Report #453728 Posted May 8, 2012 at 10:37 AM Ok, pensava que querias retornar logo ai. Responde as outras perguntas que te fiz. Pedro Martins Não respondo a duvidas por PM
AMB Posted May 8, 2012 at 10:50 AM Author Report #453735 Posted May 8, 2012 at 10:50 AM Eu quando clico no hyperlink dentro da grid tenho: http://localhost:3072/WebService1.asmx?id=492430 Quando clico no hyperlink nleitura tenho: http://localhost:3072/WebService1.asmx?op=nleitura E quando clico no invoke tenho: http://localhost:3072/WebService1.asmx/nleitura que é onde aparece <string>Erro nº processo ''</string>
Caça Posted May 8, 2012 at 10:56 AM Report #453738 Posted May 8, 2012 at 10:56 AM Esquece... Desfaz a alteração que te disse em cima para utilizar os parâmetros em vez do QueryString, estava a ver outra coisa.. Depois disso teu link devera ser mais ou menos assim http://localhost:3072/WebService1.asmx/nleitura?ID=492430 Pedro Martins Não respondo a duvidas por PM
AMB Posted May 8, 2012 at 11:00 AM Author Report #453740 Posted May 8, 2012 at 11:00 AM Então fica assim??? <WebMethod()> _ <ScriptMethod(UseHttpGet:=True)> _ Public Function nleitura() As String 'Public Function nleitura(ByVal id As Integer) As String Dim conne As String 'Dim x As String 'x = HttpContext.Current.Request.QueryString("id") x = Context.Request.QueryString("id")
Caça Posted May 8, 2012 at 11:01 AM Report #453743 Posted May 8, 2012 at 11:01 AM Sim, depois utiliza um link como o que te indiquei. Pedro Martins Não respondo a duvidas por PM
AMB Posted May 8, 2012 at 11:07 AM Author Report #453747 Posted May 8, 2012 at 11:07 AM Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.ComponentModel Imports System.Data.SqlClient Imports System.Web.Script.Services ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. ' <System.Web.Script.Services.ScriptService()> _ <System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _ <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ <ToolboxItem(False)> _ Public Class WebService1 Inherits System.Web.Services.WebService <WebMethod()> _ <ScriptMethod(UseHttpGet:=True)> _ Public Function nleitura() As String 'Public Function nleitura(ByVal id As Integer) As String Dim conne As String 'Dim x As String 'x = HttpContext.Current.Request.QueryString("id") x = Context.Request.QueryString("id") 'Dim x As String = "492414" Dim nleitura1 As String Dim nleiturat As String conne = "Data Source=localhost;Initial Catalog=DC;Integrated Security=True" Dim conn As New SqlConnection Dim comand As New SqlCommand conn.ConnectionString = conne conn.Open() comand.Connection = conn comand.CommandText = "SELECT ident FROM ps WHERE (ident = '" & id & "')" nleitura = comand.ExecuteScalar 'x = Request.QueryString["id"] 'QueryStringParameter= "ident" QueryStringField="id" If nleitura Is Nothing OrElse IsDBNull(nleitura) Then Return "Erro nº processo '" & id & "'" Else comand.CommandText = "SELECT I FROM ps WHERE ident ='" & id & "'" nleiturat = comand.ExecuteScalar If nleiturat Is Nothing OrElse IsDBNull(nleiturat) Then Return "Não existe I" System.Diagnostics.Process.Start("C:\ex\find\" + id + ".bat") System.Diagnostics.Process.Start("C:\ex\" + id + ".bat") Context.Response.Redirect("http://localhost:8080/ps/im/" + id + ".jpg") Else Dim conne1 As String conne1 = "Data Source=localhost;Initial Catalog=pb;Integrated Security=True" Dim conn1 As New SqlConnection Dim comand1 As New SqlCommand conn1.ConnectionString = conne1 conn1.Open() comand1.Connection = conn1 comand1.CommandText = "SELECT acno FROM dboy WHERE acno='" & id & "'" nleitura1 = comand1.ExecuteScalar If nleitura1 Is Nothing OrElse IsDBNull(nleitura1) Then System.Diagnostics.Process.Start("C:\ex\" + id + ".bat") Context.Response.Redirect("http://localhost:8080/ps/im/" + id + ".jpg") Else Context.Response.Redirect("http://localhost:8080/ps/im/" + id + ".jpg") End If End If End If End Function End Class Este é o meu código do webservice onde coloco o link como me indicaste?? EDIT: GeSHi alterado, utiliza vbnet em vez de asp
Caça Posted May 8, 2012 at 11:11 AM Report #453750 Posted May 8, 2012 at 11:11 AM Coloca na tua GridView. Pedro Martins Não respondo a duvidas por PM
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now