Foros del Web » Programando para Internet » ASPX (.net) »

Como acceder a un servicio Web Utilizando WebClient c#

Estas en el tema de Como acceder a un servicio Web Utilizando WebClient c# en el foro de ASPX (.net) en Foros del Web. HOla, debo acceder a un servicio web q utiliza Axis, entonces tengo problemas al utilizar el wsdl en VS2013, por lo q no me queda ...
  #1 (permalink)  
Antiguo 03/06/2015, 16:04
 
Fecha de Ingreso: diciembre-2011
Mensajes: 77
Antigüedad: 12 años, 4 meses
Puntos: 2
Como acceder a un servicio Web Utilizando WebClient c#

HOla, debo acceder a un servicio web q utiliza Axis, entonces tengo problemas al utilizar el wsdl en VS2013, por lo q no me queda otra forma q accederlo utilizando WebClient u otra forma. Lo q pasa es q el servicio utiliza Autenticacion y SSL.
Ayuda por fa.
  #2 (permalink)  
Antiguo 10/06/2015, 01:10
 
Fecha de Ingreso: noviembre-2002
Ubicación: DF
Mensajes: 1.056
Antigüedad: 21 años, 5 meses
Puntos: 37
Respuesta: Como acceder a un servicio Web Utilizando WebClient c#

No he usado AXIS.

pero para la autenticacion debieron proporcionarte un usuario y pwd.
Por lo de SSL, pues seguramente el URL a donde te conectaras tendra el protocolo "https", algo como:

linkdelwebservice = "https://dominio.com/api/login/webservice01"
Dim wbrq As HttpWebRequest = HttpWebRequest.Create(enlaceKPI)
wbrq.ContentType = "application/json; charset=utf-8"

(te tienen q decir en q formato viene la respuesta, si json o xml )
tambien si la conexion o envio de parametros (usuario y pwd es por GET o POST)

SI ES POR GET
wbrq.Method = "GET"
'Get the headers associated with the request.
Dim myWebHeaderCollection As WebHeaderCollection = wbrq.Headers
myWebHeaderCollection.Add("sessionId", sessionID) ' En mi caso me mandan un session ID luego del login
Dim RequestHttpHeaders As NameValueCollection = New NameValueCollection()

SI ES POR POST:
wbrq.Method = "POST"

'Get the headers associated with the request.
Dim myWebHeaderCollection As WebHeaderCollection = wbrq.Headers
myWebHeaderCollection.Add("sessionId", sessionID)
Dim RequestHttpHeaders As NameValueCollection = New NameValueCollection()

wbrq.Accept = "application/json"
wbrq.UserAgent = ".NET Framework Test Client"

ASI ES COMO MANDO EL USUARIO Y PWD, lo piden ademas como JSON:

dictionary.Add("username", usuarioquemedieron)
dictionary.Add("password", pwd)

jsonData = New JavaScriptSerializer().Serialize(dictionary)

wbrq.ContentLength = jsonData.Length
Dim s As StreamWriter = New StreamWriter(wbrq.GetRequestStream()) 'Cannot send a content-body with this verb-type
s.Write(jsonData)

s.Close()


RECUPERO LA RESPUESTA, en mi caso como CADENA:
Dim wbrs As HttpWebResponse = wbrq.GetResponse

stream = New StreamReader(wbrs.GetResponseStream, Encoding.GetEncoding("utf-8"))

Dim JSON_respuestaDELWS As String = ""
JSON_respuestaDELWS = stream.ReadToEnd.Trim

Etiquetas: servicio
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:37.