Android Question UknownHostException

hatzisn

Expert
Licensed User
Longtime User
Hi all,

It is my first post in this forum and I will try to be as specific as I can. I am trying to consume a .NET Web Service in my application and I am receiving an error (java.net.UknownHostException {servername.com}).

The web service definition is this:
The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.

POST /synproj/nikos/webservice.asmx HTTP/1.1
Host: servername.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://trial.net/CheckIfUserExist"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<CheckIfUserExist xmlns="http://trial.net/">
<sWSUser>string</sWSUser>
</CheckIfUserExist>
</soap:Body>
</soap:Envelope>



HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<CheckIfUserExistResponse xmlns="http://trial.net/">
<CheckIfUserExistResult>string</CheckIfUserExistResult>
</CheckIfUserExistResponse>
</soap:Body>
</soap:Envelope>


The post and response bellow is shown in chrome when I try to access my webservice via the internet. The host exists and is alive. I am using an Android 2.3.3 emulator.
Here is my code (the file that I read is the POST XML bellow and I change the string to the username).
I have used the OCR Examble to do so... What am I doing wrong?

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim ht As HttpJob
    Dim strResponse As String
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.
    Private btnTry As Button
    Private btnShow As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
   
    Activity.LoadLayout("Main")
   
   
End Sub

Sub JobDone(job As HttpJob)
ProgressDialogHide
'ToastMessageShow (job.JobName ,False)
If job.Success Then
    ToastMessageShow("Success",False)
    ToastMessageShow(job.GetString,True)
Else
    ToastMessageShow("No Success", False)
    ToastMessageShow(job.ErrorMessage,True)
End If

End Sub


Sub Activity_Resume
   
    strResponse = File.GetText(File.DirAssets,"trial.txt")
    strResponse = strResponse.Replace("$string$","hatzisn")
   
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub



Sub btnTry_Click
    ht.Initialize("WS",Me)
    ProgressDialogShow ("Connecting...")
    ht.poststring("http://servername.com/synproj/nikos/webservice.asmx", strResponse)
    ht.GetRequest.SetContentType("text/xml; charset=utf-8")
    ht.GetRequest.SetHeader("SOAPAction", """http://trial.net/CheckIfUserExist""")
End Sub
Sub btnShow_Click
    ToastMessageShow(strResponse,True)
End Sub
 

hatzisn

Expert
Licensed User
Longtime User
Hi Erel,

thanks a lot for your quick response. The server is not local. It is located on the Internet. I suspect
that it has something to do with the sub-domains of the address (it is f.e. apps.sectorname.schoolname.universityname.gr)
and I do not know how they define the sub-domains (internally or externally)... I was told that they define it as cname.
Could this be a problem for the program?

Thanks again,
Nikolaos
 
Last edited:
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
I tried to use a different server and I get the same result. I then changed to the http://www.google.com
and I still get the java.net.UknownHostException www.google.com. That can't be true. Something else is
the problem...
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Hi Erel,

Sorry for not replying immediately. No I am running on an emulator. I googled it a little and
I 've found that if you ping the server and get its IP address and use this IP instead it is working
properly. I still did not manage to connect to my web service because the cname points to a subfolder
of the main server which is unknown to me for now until I get a response from the IT department.
Thanks anyway for your help. I hope my answer helps somebody else...

Cheers,
Nikolaos
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…