Error 500 (Internal Server Error) during POST REQUEST in Web Service written in C#

consultatech4android

Member
Licensed User
Good morning to all of the Forum.

I'm writing a routine sync tables between ANDROID smartphone and a web service that was written in C # (Visual Studio 2008), originally to serve Windows Mobile devices. The intention is to replace the Smartpones Windows Mobile for ANDROID gradually, so it is not possible to change the Web Service.
Following examples posted in this forum and elsewhere, I wrote the following routine:

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim parserPalmConfig As SaxParser
   Dim HttpWEB As HttpClient

   'Objetos
   Dim PalmConfig    As PalmconfigWS

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("T10_Sincr_Base")

   Retorna_Tabelas_WS
   

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Retorna_Tabelas_WS As Boolean
   Dim request As HttpRequest
   Dim Endereco, Pr As String
   Dim Para() As Byte
   Dim Connect As Boolean
   Dim Inp As InputStream
   Dim conv As ByteConverter

   Pr = ""

   Connect = True

   HttpWEB.Initialize("HttpWEB")


   Endereco = "http://atecnologia.no-ip.info/wsAplicacaoVendaArm/Service.asmx/RetornaPalmConfig"
   Pr = "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "utf-8" & Chr(34) & "?>" & CRLF & _
       "<soap12:Envelope xmlns:xsi=" & Chr(34) & "http://www.w3.org/2001/XMLSchema-instance" & Chr(34) & " xmlns:xsd=" & Chr(34) & "http://www.w3.org/2001/XMLSchema" & Chr(34) & " xmlns:soap12=" & Chr(34) & "http://www.w3.org/2003/05/soap-envelope" & Chr(34) & ">" & CRLF & _
       "<soap12:Body>" & CRLF & _
       "<RetornaAtividades xmlns=" & Chr(34) & "http://aplicacaovenda.org/" & Chr(34) & " />" & CRLF & _
       "</soap12:Body>" & CRLF & _
       "</soap12:Envelope>"

   Para = conv.StringToBytes(Pr,"UTF-8")
   Inp.InitializeFromBytesArray(Para, 0, Para.Length)   
   request.InitializePost(Endereco, Inp, Para.Length)
   request.SetContentEncoding("UTF-8")
   request.Timeout = 10000 'set timeout to 10 seconds
   Connect = HttpWEB.Execute(request, 1)
   ProgressDialogShow("Conectando ao Web Service...")

   Return Connect
End Sub

Sub HttpWEB_ResponseSuccess (Response As HttpResponse, TaskId As Int)
   Dim result As String
   Dim Inp As InputStream

   Log("ResponseSuccess")
   ProgressDialogHide

   result = Response.GetString("UTF8") 'Convert the response to a string
   Log(result)
   'Msgbox(result, "")

   If File.Exists(File.DirDefaultExternal,"palmconfig.xml") = True Then
      File.Delete(File.DirDefaultExternal,"palmconfig.xml")
   End If
   
   File.WriteString(File.DirDefaultExternal,"palmconfig.xml",result)
   
   parserPalmConfig.Initialize

   'parse the xml file
   Inp = File.OpenInput(File.DirDefaultExternal, "palmconfig.xml")
   parserPalmConfig.parse(Inp, "parserPalmConfig")
   Inp.Close
   File.Delete(File.DirDefaultExternal, "palmconfig.xml")

End Sub

Sub HttpWEB_ResponseError (Reason As String, StatusCode As Int, TaskId As Int)
   Dim msg As String
   Log(Reason)
   Log(StatusCode)
   ProgressDialogHide
   msg = "Erro ao conectar no Web Service."
   If Reason <> Null Then
      msg = msg & CRLF & "(" & StatusCode & ") " & Reason
   End If
   ToastMessageShow (msg, True)
End Sub

'#########################################################################################################
'# PALMCONFIG                                                                                            #
'#########################################################################################################
Sub parserPalmConfig_StartElement (Uri As String, Name As String, Attributes As Attributes)

End Sub

Sub parserPalmConfig_EndElement (Uri As String, Name As String, Text As StringBuilder)
   Dim nContPalm As Int
   ToastMessageShow("PalmConfig" & CRLF & Uri & CRLF & Name & CRLF & Text,False)

   If Name = "PalmVendor" Then
      PalmConfig.Initialize
      PalmConfig.setPalmVendor(Text)
   End If
   If Name = "UltimaAlt" Then
      PalmConfig.setUltimaAlt(DateTime.DateParse(Text.ToString.SubString2(8,9)&"/"&Text.ToString.SubString2(5,6)&"/"&Text.ToString.SubString2(0,3)))
   End If
   If Name = "Vendedor" Then
      PalmConfig.setVendedor(Text)
   
      nContPalm = Main.MobileDB.ExecQuerySingleResult("Select COUNT(*) FROM palmconfig WHERE PalmVendor = " & PalmConfig.getPalmVendor())

      If nContPalm = 0 Then
         SQL =  "INSERT INTO palmconfig ( PalmVendor, " _
              &"                         UltimaAlt, " _
              &"                         Vendedor )" _
               &"                VALUES ( " & PalmConfig.getPalmVendor() & ", " _
               &"                         " & PalmConfig.getUltimaAlt()   & ", " _
               &"                         " & PalmConfig.getVendedor()    & " )"
      Else
         SQL =  "UPDATE palmconfig SET UltimaAlt  = " & PalmConfig.getUltimaAlt() & ", " _
              &"                      Vendedor   = " & PalmConfig.getVendedor() _
              &"                WHERE PalmVendor = " & PalmConfig.getPalmVendor() 
      End If
      
      Main.MobileDB.ExecNonQuery( SQL )
   End If

End Sub


In the event HttpWEB_ResponseError is pointing the error 500 "Internal Server Error"

A description of the services the Web Service:

http://atecnologia.no-ip.info/wsAplicacaoVendaArm/Service.asmx?WSDL

The descriptive call and response method RetornaPalmConfig Web Service:

"http://atecnologia.no-ip.info/wsAplicacaoVendaArm/Service.asmx?op=RetornaPalmConfig"


Note: I used the 3.6.1 software SoapUI to test the web service and it returns the following requests:

in SOAP 1.1:

POST "http://atecnologia.no-ip.info/wsAplicacaoVendaArm/Service.asmx" HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "http://aplicacaovenda.org/RetornaPalmConfig"
User-Agent: Jakarta Commons-HttpClient/3.1
Host: atecnologia.no-ip.info
Content-Length: 224

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:apl="http://aplicacaovenda.org/">
<soapenv:Header/>
<soapenv:Body>
<apl:RetornaPalmConfig/>
</soapenv:Body>
</soapenv:Envelope>


in SOAP 1.2:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:apl="http://aplicacaovenda.org/">
<soap:Header/>
<soap:Body>
<apl:RetornaPalmConfig/>
</soap:Body>
</soap:Envelope>



Can someone help me, I'm very short deadline to deliver the service a few days ago and now I'm researching and testing. Now I can not take, so I'm using the forum.
 

consultatech4android

Member
Licensed User
Solved...

As reported in the thread started by the Boy River jroriz ( http://www.basic4ppc.com/forum/basic4android-updates-questions/11790-very-basic-webservice-consumption.html ) Only changed the web.config configuration file of the Web Service, adding:

<webServices>
**** <protocols>
******* <add name="HttpPost"/>
******* <add name="HttpGet"/>
**** </ Protocols>
</ WebServices>

Then realized the following change in the code:

B4X:
Sub Retorna_Tabelas_WS As Boolean
    Dim Endereco As String
    Dim request As HttpRequest
    Dim Connect As Boolean

    Connect = True

    HttpWEB.Initialize("HttpWEB")

    Endereco = "http://atecnologia.no-ip.info/wsAplicacaoVendaArm/Service.asmx/RetornaPalmConfig"

    request.initializeget(Endereco)
    request.Timeout = 10000 'set timeout to 10 seconds
    Connect = HttpWEB.Execute(request, 1)
    ProgressDialogShow("Conectando ao Web Service...")

    Return Connect
End Sub


With this I am getting the event via XML HttpWEB_ResponseSuccess

Thank jroriz by Erel and collaboration, and there is the post for future reference.

:sign0098:
 
Upvote 0
Top