Calling a webservice: ClientProtocolException

Kiffi

Well-Known Member
Licensed User
Longtime User
Hello,

i want to call a simple function (HelloWorld) inside my webservice (Service.asmx):

Code:
Sub Activity_Create(FirstTime As Boolean)

    If FirstTime Then
        HttpClient1.Initialize("HttpClient1")
    End If

   Dim URL As String
   URL = "http://192.168.1.37:8023"

   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 & "    <HelloWorld xmlns='http://my.webservicetest.org/' />"
   XML = XML & "  </soap12:Body>"
   XML = XML & "</soap12:Envelope>"
   
   XML = XML.Replace("'", Chr(34))

   Dim request As HttpRequest
   request.InitializePost2(URL, XML.GetBytes("UTF8"))

   ' POST /Service.asmx HTTP/1.1
   ' Host: 192.168.1.37
   ' Content-Type: application/soap+xml; charset=utf-8
   ' Content-Length: length

   request.SetHeader("POST", "/Service.asmx HTTP/1.1")
   request.SetHeader("Host", "192.168.1.37")
   request.SetHeader("Content-Type", "application/soap+xml; charset=utf-8")
   request.SetHeader("Content-Length", XML.Length)
   
   request.Timeout = 10000 
   If HttpClient1.Execute(request, 1) = False Then Return
   ProgressDialogShow("One moment please...")
   
End Sub

unfortunately i get an Exception: org.apache.http.client.ClientProtocolException.

My Question: is this the right way to call a webservice?
What am I doing wrong?

Thanks in advance & Greetings ... Kiffi
 
Hello,

i want to call a simple function (HelloWorld) inside my webservice (Service.asmx):

Code:
Sub Activity_Create(FirstTime As Boolean)

    If FirstTime Then
        HttpClient1.Initialize("HttpClient1")
    End If

   Dim URL As String
   URL = "http://192.168.1.37:8023"

   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 & "    <HelloWorld xmlns='http://my.webservicetest.org/' />"
   XML = XML & "  </soap12:Body>"
   XML = XML & "</soap12:Envelope>"
   
   XML = XML.Replace("'", Chr(34))

   Dim request As HttpRequest
   request.InitializePost2(URL, XML.GetBytes("UTF8"))

   ' POST /Service.asmx HTTP/1.1
   ' Host: 192.168.1.37
   ' Content-Type: application/soap+xml; charset=utf-8
   ' Content-Length: length

   request.SetHeader("POST", "/Service.asmx HTTP/1.1")
   request.SetHeader("Host", "192.168.1.37")
   request.SetHeader("Content-Type", "application/soap+xml; charset=utf-8")
   request.SetHeader("Content-Length", XML.Length)
   
   request.Timeout = 10000 
   If HttpClient1.Execute(request, 1) = False Then Return
   ProgressDialogShow("One moment please...")
   
End Sub

unfortunately i get an Exception: org.apache.http.client.ClientProtocolException.

My Question: is this the right way to call a webservice?
What am I doing wrong?

Thanks in advance & Greetings ... Kiffi

Actually i'm calling my webservice how if call from a browser

Code:
Sub CaricaTavoli()
             Dim URLServer, URLTavoli As String   
             Dim request As HttpRequest
   Dim LaSala, Flag, CallTheService As String
             URLTavoli = "WebM_ListaTavText"
             URLServer== "http://192.168.1.2/Webristserv.asmx/"
   LaSala="SalaA"
   Flag="X"   
   CallTheService=URLServer & URLTavoli & "?CodSala=" & LaSala & "&Flag=" & Flag
   request.InitializeGet(Chiamata)
   request.Timeout = 10000
   If HttpClient1.Execute(request, 1) = False Then 
      Return 
   End If
   ProgressDialogShow("Attendere ...")
End Sub

The great problem is translate the response.
I've changed all the responses of the webservice in a simply single string
with fields separated by ";".

Example response of the precedent call:

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/WebProject1/WebRistServ">63720893;ANT;5;Carpaccio spada;2;19;38;63720894;PRI;440;Pasta ragu' - ;2;4,5;9;63720895;CA2;81;Scaloppa di Vitello con Pro;2;21;42;</string>

after isolated the string into <string> and </string>
i can inspect the fields with:

Code:
                         Carray= Regex.Split(";",WebResult)
      B=0
      Dim Tbsale(10) As RecordSale
      For a = 0 To Carray.Length -1 Step 3
         TbSale(b).Id_Sala=carray(a)
         Tbsale(b).Descr_Sala=carray(a+1)
         Tbsale(b).Cod_Default_Somm=carray(a+2)
         B=B+1
      Next

Your or other experience ?
Bye
:sign0098:
 
Upvote 0
Hello Erel,

There is no need to manually set those headers.
Try to comment the SetHeaders code (at least the first two).

great! After removing POST, Host and Content-Length, it works! :icon_clap:

Code:
Sub Activity_Create(FirstTime As Boolean)

    If FirstTime Then
        HttpClient1.Initialize("HttpClient1")
    End If

   Dim URL As String
   URL = "http://192.168.1.37:8023/Service.asmx"

   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 & "    <HelloWorld xmlns='http://my.webservicetest.org/' />"
   XML = XML & "  </soap12:Body>"
   XML = XML & "</soap12:Envelope>"
   
   XML = XML.Replace("'", Chr(34))

   Dim request As HttpRequest
   request.InitializePost2(URL, XML.GetBytes("UTF8"))

   request.SetHeader("Content-Type", "application/soap+xml; charset=utf-8")

   request.Timeout = 10000 
   If HttpClient1.Execute(request, 1) = False Then Return
   ProgressDialogShow("One moment please...")
   
End Sub

Thanks a lot & Greetings ... Kiffi
 
Upvote 0
Back
Top