suresh pondicherry
asked on
Calling REST service from VB.NET using GET and POST method
Hi All,
I have to call Java rest services from VB.NET application. I could call the service successfully if use the port 8080. Without the port number when i call the actual URL, getting
{"The remote server returned an error: (401) Unauthorized."}
'e.Result' threw an exception of type 'System.Reflection.TargetI nvocationE xception'
Kind regards,
Pooja
I have to call Java rest services from VB.NET application. I could call the service successfully if use the port 8080. Without the port number when i call the actual URL, getting
{"The remote server returned an error: (401) Unauthorized."}
'e.Result' threw an exception of type 'System.Reflection.TargetI
Kind regards,
Pooja
If your service is hosted using port 8080, why wouldn't you be passing the port number?
ASKER
Hi Kaufmed,
Consider this is Java Rest url (http://devName/stored/status). I have to post the xml file in body of the url.
Earlier i could do use Get method and pass xml data using POST method using the url (http://devName:8080/stored/status).
This is a working code which uses port 8080,
Dim pwd As String = String.Empty
Dim reqURL As String = String.Empty
reqURL = "http://devName:8080/stored/status"
WebRequest.RegisterPrefix( reqURL, WebRequestCreator.ClientHt tp)
wc = New WebClient()
pwd = String.Format("{0}:{1}", username, password)
Dim authbytes As [Byte]() = Encoding.UTF8.GetBytes(pwd .ToCharArr ay())
wc.Headers(HttpRequestHead er.Authori zation) = "Basic " & Convert.ToBase64String(aut hbytes)
AddHandler wc.DownloadStringCompleted , AddressOf wc_DownloadStringCompleted
wc.DownloadStringAsync(New Uri(reqURL))
Kind regards,
Pooja
Consider this is Java Rest url (http://devName/stored/status). I have to post the xml file in body of the url.
Earlier i could do use Get method and pass xml data using POST method using the url (http://devName:8080/stored/status).
This is a working code which uses port 8080,
Dim pwd As String = String.Empty
Dim reqURL As String = String.Empty
reqURL = "http://devName:8080/stored/status"
WebRequest.RegisterPrefix(
wc = New WebClient()
pwd = String.Format("{0}:{1}", username, password)
Dim authbytes As [Byte]() = Encoding.UTF8.GetBytes(pwd
wc.Headers(HttpRequestHead
AddHandler wc.DownloadStringCompleted
wc.DownloadStringAsync(New
Kind regards,
Pooja
In my understanding, the concept of REST restrict you to one single port number. A RESTful service is one that takes advantage of existing HTTP verbs (and ones you add) to transfer data. The server name and port number are just a way of identifying where the service resides. If you are hosting your service on port 8080, then you need to access your service via port 8080. If you want to access your service with no port number, then you need to configure your service to run on port 80--the standard HTTP port.
You can certainly use POST to transfer data to your service. You need to tell this to your WebClient, though. For example:
You can certainly use POST to transfer data to your service. You need to tell this to your WebClient, though. For example:
Dim wc As New WebClient()
Dim xmlData() As Byte = System.IO.File.ReadAllBytes(@"C:\path\to\xml\file.xml")
wc.Credentials = new System.Net.NetworkCredential(username, password)
wc.UploadData("http://devName:8080/stored/status", "POST", xmlData)
the concept of REST restrict you to one single port number.Correction: the concept of REST doesn't restrict you to one single port number.
ASKER
Hi Kaufmed,
Thanks for the reply. First thing is i don't need to use any port numbers. Second, i could not get method name UploadData.
What i heard from the person who published the service is to call google.com using GET method. If that works ,i have to apply the same code to call the java rest service..
Also i am using xml string here , not a file. I really appreciate if i got helped. Thanks for the support and eagerly expecting some tips since i am searching the answer for last 2 weeks..
Kind regards,
Pooja
Thanks for the reply. First thing is i don't need to use any port numbers. Second, i could not get method name UploadData.
What i heard from the person who published the service is to call google.com using GET method. If that works ,i have to apply the same code to call the java rest service..
Also i am using xml string here , not a file. I really appreciate if i got helped. Thanks for the support and eagerly expecting some tips since i am searching the answer for last 2 weeks..
Kind regards,
Pooja
ASKER
Hi,
Typing mistake...
call google.com or cnn.com or yahoo.com, etc... and try to get their html (that's make sure my code will work on calling java service). is this make sense?
Kind regards,
Pooja
Typing mistake...
call google.com or cnn.com or yahoo.com, etc... and try to get their html (that's make sure my code will work on calling java service). is this make sense?
Kind regards,
Pooja
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Solution is to establish the connection through handler.