
Error 403 web service
Publicado por David (1 intervención) el 04/04/2014 10:27:06
Buenos dias:
Soy nuevo en Vb.net y necesito ayuda urgente.
Llevo toda la semana pegandome con un web service. Necestio mandar un xml como el siguiente pero me sale continuamente error 403 acces forbidden.
Os paso tambien el codigo de como lo hago.
Paso tambien el codigo de como calculo el nonce porque no estoy seguro de si es correcto.
Si me pudieseis ayudar quedaria infinitamente agradecido.
Saludos.
Soy nuevo en Vb.net y necesito ayuda urgente.
Llevo toda la semana pegandome con un web service. Necestio mandar un xml como el siguiente pero me sale continuamente error 403 acces forbidden.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<soapenv:Envelope xmlns:dat="http://www.riojasalud.es/edi/recetaelectronica/DatosXML" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-3">
<wsse:Username>GESTI</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">21GESTI</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">GEQHRuDqiYToUhmBvO+oq2TlDb8=</wsse:Nonce>
<wsu:Created>2014-04-04T10:23:32.271Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<dat:Peticion>
<dat:Accion>ObtenerPrescripcionesDispensables</dat:Accion>
<dat:Mensaje>
<![CDATA[<?xml version="1.0" encoding="UTF-8"?> <ns0:PET_ObtenerPrescripcionesDispensables xmlns:ns0 = "http://www.riojasalud.es/edi/recetaelectronica/mensajes/farmacia"><IdPaciente>RDPR560327906012</IdPaciente><TipoIdPaciente>1</TipoIdPaciente><Farmacia>1</Farmacia><Usuario>GESTIFARMA</Usuario></ns0:PET_ObtenerPrescripcionesDispensables>]]></dat:Mensaje>
</dat:Peticion>
</soapenv:Body>
</soapenv:Envelope>
Os paso tambien el codigo de como lo hago.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Dim objRequest As HttpWebRequest = CType(WebRequest.Create("https://www.riojasalud.es/RecetaElectronicaDes/Farmacias"), HttpWebRequest)
'Dim StrData As String
'Dim objXMLDoc As New System.Xml.XmlDocument()
'objXMLDoc.Load(POSTData) 'xml data I need to send
'StrData = objXMLDoc.OuterXml
'StrData = POSTData //POSTDATA CONTIENE EL XML DE ARRIBA
objRequest.Method = "POST"
Dim encoding As New System.Text.ASCIIEncoding()
Dim byte1 As Byte() = System.Text.Encoding.UTF8.GetBytes(POSTData)
objRequest.ContentLength = byte1.Length
objRequest.ContentType = "text/xml;charset=UTF-8"
objRequest.KeepAlive = False
'objRequest.s()
Dim streamToSend As Stream = objRequest.GetRequestStream()
'Response.Write("Number of characters returned: " & byte1.Length & "<br>")
streamToSend.Write(byte1, 0, byte1.Length)
streamToSend.Close()
Dim objResponse As HttpWebResponse = objRequest.GetResponse()
Dim StreamReader As StreamReader
StreamReader = New StreamReader(objResponse.GetResponseStream())
Dim xmlDoc As New XmlDocument()
xmlDoc.LoadXml(StreamReader.ReadToEnd())
'Response.Write("RETURN XML:" & xmlDoc.InnerXml)
Dim sr As New System.IO.StringReader(xmlDoc.InnerXml)
Dim doc As New Xml.XmlDocument
doc.Load(sr)
Dim reader As New Xml.XmlNodeReader(doc)
While reader.Read()
Select Case reader.NodeType
Case Xml.XmlNodeType.Element
If reader.Name = "response" Then
'Response.Write(reader.GetAttribute("msg"))
End If
If reader.Name = "reaction" Then
'Response.Write("<br />ID " & reader.GetAttribute("id"))
End If
End Select
End While
StreamReader.Close()
Paso tambien el codigo de como calculo el nonce porque no estoy seguro de si es correcto.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Protected Function crearNonce() As String
Dim usn As String = "GESTI"
Dim pwd As String = "21GESTI"
Dim created As DateTime = DateTime.Now.ToUniversalTime()
Dim nonce As String = getNonce()
Dim nonceToSend As String = Convert.ToBase64String(Encoding.UTF8.GetBytes(nonce))
Dim createdStr As String = created.ToString("yyyy-MM-ddTHH:mm:ss.271Z")
Dim passwordToSend As String = GetSHA1String(nonce + createdStr + pwd)
Return passwordToSend
End Function
Protected Function getNonce() As String
Dim phrase As String = Guid.NewGuid().ToString()
Return phrase
End Function
Protected Function GetSHA1String(ByVal phrase As String) As String
Dim sha1Hasher As SHA1CryptoServiceProvider = New SHA1CryptoServiceProvider()
Dim hashedDataBytes As Byte() = sha1Hasher.ComputeHash(Encoding.UTF8.GetBytes(phrase))
Dim test As String = Convert.ToString(hashedDataBytes)
Return Convert.ToBase64String(hashedDataBytes)
End Function
Si me pudieseis ayudar quedaria infinitamente agradecido.
Saludos.
Valora esta pregunta


0