Spanish Webservices con ASMX y mas de un parámetro

Tengo un webservice asmx realizado en .net funcionando. Utilizo IIS.
En B4A cuando utilizo solamente un parámetro funciona perfecto pero cuando son dos o mas me regresa NULL.
Nota: Aunque diga sumanumeros o hable de numeros, utilizo strings.
Gracias.

Este es mi codigo actual en B4A

B4X:
Private Sub CmdInicia_Click
    IniciaWebService ("Elon","Musk")
End Sub
Sub IniciaWebService(NumeroA As String, NumeroB As String)
    Dim job1 As HttpJob
    Dim XML As String
   
    XML = ""
    XML = XML & "<?xml version='1.0' encoding='utf-8'?>"
    XML = XML & "<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'>"
    XML = XML & "<soap12:Body>"
    XML = XML & "<SumaNumeros xmlns='http://192.168.0.7/sumanumeros/'>"
    XML = XML & "<NumeroA>" & NumeroA & "</NumeroA>"
    XML = XML & "<NumeroB>" & NumeroB & "</NumeroB>"
    XML = XML & "</SumaNumeros>"
    XML = XML & "</soap12:Body>"
    XML = XML & "</soap12:Envelope>"
    XML = XML.Replace("'", Chr(34))
    job1.Initialize("JOBSOAP", Me)
    job1.PostString ("http://192.168.0.7/sumanumeros/WSSumaNumeros.asmx", XML)
    job1.GetRequest.SetContentType("application/soap+xml")
End Sub

Sub JobDone (Job As HttpJob)
    Dim resultat As String
    If Job.Success Then
        Dim Res As String
        Res = Job.GetString
        Select Job.JobName
            Case "JOBSOAP"
                resultat = xmlGetTagContent(Res,"SumaNumerosResult")
                MsgboxAsync(resultat,"resultat")
        End Select
    Else
        MsgboxAsync( Job.errormessage , "Error")
    End If
    Job.Release
End Sub
Sub xmlGetTagContent(xml As String, tag As String) As String
    Dim i, j As Int

    'Find start-tag:
    i = xml.IndexOf("<" & tag & ">")
    If i < 0 Then i = xml.IndexOf("<" & tag & " ")
    If i < 0 Then Return Null
    i = xml.IndexOf2(">", i) + 1
  
    'Find stop-tag:
    j = xml.LastIndexOf("</" & tag & ">")
    If i < j Then
        Return xml.SubString2(i, j)
    Else
        Return Null
    End If

End Sub

Mi webservice

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel

' Para permitir que se llame a este servicio web desde un script, usando ASP.NET AJAX, quite la marca de comentario de la línea siguiente.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://192.168.0.7/sumanumeros/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class WSSumaNumeros
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function SumaNumeros(A As String, B As String) As String
Dim Junta As String
Junta = A & B
Return Junta
End Function
End Class
 
Last edited:

josejad

Expert
Licensed User
Longtime User
Hola Jimmy:

A qué te refieres con "más de un parámetro"?
Te refieres a lo que pasas en el XML con "<NumeroA>" & NumeroA & "</NumeroA>"? O en el job.Poststring?

Por cierto, no deberías usar el jobdone y usar wait for:


saludos,
 
Hola Jimmy:

A qué te refieres con "más de un parámetro"?
Te refieres a lo que pasas en el XML con "<NumeroA>" & NumeroA & "</NumeroA>"? O en el job.Poststring?

Por cierto, no deberías usar el jobdone y usar wait for:


saludos,

Hola. Gracias por tu tiempo.
Mi webservice pide dos parametros para funcionar

Esto esta en visual basic net.
Public Function SumaNumeros(A As String, B As String) As String
Dim Junta As String
Junta = A & B
Return Junta
End Function

Me pide dos Strings A y B y al final los junta en una sola cadena.
Cuando hago el proceso solo con un parámetro, por ejemplo, A funciona perfecto pero ya con más de un parámetro me regresa null dentro del jobdone
.
En B4A me imagino que debo de meter los valores de esos parámetros pero creo que ahí me esta fallando como debe de ser la forma correcta en el XML.
 

Attachments

  • 1.png
    1.png
    3.3 KB · Views: 129
  • 2.png
    2.png
    3.5 KB · Views: 130
Publica el detalle del webservice, utiliza el navegador web:

Gracias por tu tiempo. Pongo lo que pide el webservice y el resultado.
Mi pregunta es como hacerlo funcionar en b4a con más de un parámetro.
 

Attachments

  • 1.png
    1.png
    3.3 KB · Views: 134
  • 2.png
    2.png
    3.5 KB · Views: 137

TILogistic

Expert
Licensed User
Longtime User
El problema no esta en la llamada del JOB es tu webservice que solo acepta 2 parámetros.

si deseas enviar mas parámetros debes repetir la llamada al JOB .

Saludos.
 

TILogistic

Expert
Licensed User
Longtime User
Aquí tiene un Ejemplo:

No probado

B4X:
Private Sub CmdInicia_Click
    Dim WSLink As String = "http://192.168.0.7/sumanumeros/WSSumaNumeros.asmx"
  
    Wait For(WSPostURL(WSLink, IniciaWebService ("JOB","1"))) Complete (Result As String)
    Log(xmlGetTagContent(Result,"SumaNumerosResult"))
  
    Wait For(WSPostURL(WSLink, IniciaWebService ("JOB","2"))) Complete (Result As String)
    Log(xmlGetTagContent(Result,"SumaNumerosResult"))
End Sub

Public Sub IniciaWebService(NumeroA As String, NumeroB As String) As String
    Dim XML As String
    XML = ""
    XML = XML & "<?xml version='1.0' encoding='utf-8'?>"
    XML = XML & "<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'>"
    XML = XML & "<soap12:Body>"
    XML = XML & "<SumaNumeros xmlns='http://192.168.0.7/sumanumeros/'>"
    XML = XML & "<NumeroA>" & NumeroA & "</NumeroA>"
    XML = XML & "<NumeroB>" & NumeroB & "</NumeroB>"
    XML = XML & "</SumaNumeros>"
    XML = XML & "</soap12:Body>"
    XML = XML & "</soap12:Envelope>"
    XML = XML.Replace("'", Chr(34))
    Return XML
End Sub

Public Sub xmlGetTagContent(xml As String, tag As String) As String
    Dim i, j As Int

    'Find start-tag:
    i = xml.IndexOf("<" & tag & ">")
    If i < 0 Then i = xml.IndexOf("<" & tag & " ")
    If i < 0 Then Return Null
    i = xml.IndexOf2(">", i) + 1
  
    'Find stop-tag:
    j = xml.LastIndexOf("</" & tag & ">")
    If i < j Then
        Return xml.SubString2(i, j)
    Else
        Return Null
    End If

End Sub

Public Sub WSPostURL(LinkURL As String, Parameter As String) As ResumableSub
    Dim ResultURL As String
    Dim j As HttpJob
    Try
        j.Initialize("", Me)
        j.PostString (LinkURL, Parameter)
        j.GetRequest.SetContentType("application/soap+xml")
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            ResultURL = j.GetString
        Else
            ResultURL = j.ErrorMessage
        End If
        j.Release
    Catch
        ResultURL = LastException.Message
    End Try
    Return ResultURL
End Sub
 
Last edited:
Aquí tiene un Ejemplo:

No probado

B4X:
Private Sub CmdInicia_Click
    Dim WSLink As String = "http://192.168.0.7/sumanumeros/WSSumaNumeros.asmx"
 
    Wait For(WSPostURL(WSLink, IniciaWebService ("JOB","1"))) Complete (Result As String)
    Log(xmlGetTagContent(Result,"SumaNumerosResult"))
 
    Wait For(WSPostURL(WSLink, IniciaWebService ("JOB","2"))) Complete (Result As String)
    Log(xmlGetTagContent(Result,"SumaNumerosResult"))
End Sub

Public Sub IniciaWebService(NumeroA As String, NumeroB As String) As String
    Dim XML As String
    XML = ""
    XML = XML & "<?xml version='1.0' encoding='utf-8'?>"
    XML = XML & "<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'>"
    XML = XML & "<soap12:Body>"
    XML = XML & "<SumaNumeros xmlns='http://192.168.0.7/sumanumeros/'>"
    XML = XML & "<NumeroA>" & NumeroA & "</NumeroA>"
    XML = XML & "<NumeroB>" & NumeroB & "</NumeroB>"
    XML = XML & "</SumaNumeros>"
    XML = XML & "</soap12:Body>"
    XML = XML & "</soap12:Envelope>"
    XML = XML.Replace("'", Chr(34))
    Return XML
End Sub

Public Sub xmlGetTagContent(xml As String, tag As String) As String
    Dim i, j As Int

    'Find start-tag:
    i = xml.IndexOf("<" & tag & ">")
    If i < 0 Then i = xml.IndexOf("<" & tag & " ")
    If i < 0 Then Return Null
    i = xml.IndexOf2(">", i) + 1
 
    'Find stop-tag:
    j = xml.LastIndexOf("</" & tag & ">")
    If i < j Then
        Return xml.SubString2(i, j)
    Else
        Return Null
    End If

End Sub

Public Sub WSPostURL(LinkURL As String, Parameter As String) As ResumableSub
    Dim ResultURL As String
    Dim j As HttpJob
    Try
        j.Initialize("", Me)
        j.PostString (LinkURL, Parameter)
        j.GetRequest.SetContentType("application/soap+xml")
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            ResultURL = j.GetString
        Else
            ResultURL = j.ErrorMessage
        End If
        j.Release
    Catch
        ResultURL = LastException.Message
    End Try
    Return ResultURL
End Sub

Gracias amigo por tu tiempo.
Trataré
 
Top