[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 591
  • Last Modified:

Call restful webservice in VB.NET, SL4

Hi ,
Advance thanks. How to call restful webservice from vb.net and am using SL4.0. I need to pass xdocument to the service. I don't know how to call the restful webservice. Can you help me?

Kind regards,
Pooja
0
poojasureshkumar
Asked:
poojasureshkumar
  • 8
  • 3
2 Solutions
 
poojasureshkumarAuthor Commented:
Hi CodeCruiser,
Thanks. Please find my code below.
Private WithEvents wc As WebClient

public Sub callws()
Xstr=GetXDocument()
 AddHandler wc.OpenReadCompleted, AddressOf wc_OpenReadCompleted
        wc.OpenReadAsync(New Uri(String.Format(requestString, xmlStr)))
end sub

Private Sub wc_OpenReadCompleted(ByVal sender As Object, ByVal e As OpenReadCompletedEventArgs)
        Dim resultXml As XElement
        resultXml = XElement.Load(e.Result)
End Sub



I am getting this exception,
message           "An exception occurred during the operation, making the result invalid.  Check InnerException for exception details."          String

-                              InnerException {System.Security.SecurityException ---> System.Security.SecurityException: Security error.     at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)     at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)     at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__1(Object sendState)     --- End of inner exception stack trace ---     at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)     at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)     at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)     at System.Net.WebClient.OpenReadAsyncCallback(IAsyncResult result)}  System.Exception


What's this error? what change i need to make in my end? How to verify the url is working correctly?

Kind regards,
Pooja
0
 
CodeCruiserCommented:
Which tutorial are you following?
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
poojasureshkumarAuthor Commented:
0
 
CodeCruiserCommented:
Is your service working otherwise with other clients?
0
 
poojasureshkumarAuthor Commented:
Hi CodeCruiser,
How to test it? I have worked only on calling the parameterized call over the webservice. Tis restful service is unfamiliar to me.

Kind regards,
Pooja
0
 
poojasureshkumarAuthor Commented:
Hi CodeCruiser,
Even if i tried with
requestString =  "http://google.com" , i am getting this same error

+            e.Result      {System.Reflection.TargetInvocationException: An exception occurred during the operation, making the result invalid.  Check InnerException for exception details. ---> System.Security.SecurityException ---> System.Security.SecurityException: Security error.     at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)     at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)     at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__1(Object sendState)     --- End of inner exception stack trace ---     at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)     at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)     at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)     at System.Net.WebClient.OpenReadAsyncCallback(IAsyncResult result)     --- End of inner exception stack trace ---     at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()     at System.Net.OpenReadCompletedEventArgs.get_Result()}      System.Reflection.TargetInvocationException


Kind regards,
Pooja
0
 
poojasureshkumarAuthor Commented:
Hi,
I can call the restful service (handshake) , now  i am struggling here to pass xml data into body of restful service. I am seeing security exception and i couldn't fix that error . Anybody here to help me, please.


Kind regards,
Pooja
0
 
poojasureshkumarAuthor Commented:
Hi,
I could even pass the xml into service. Able to update target database successfully.


I am using the port 8080, without the port 8080, i could not do either GET or POST.
Getting
'e.Result' threw an exception of type 'System.Reflection.TargetInvocationException'
inner exception : {"The remote server returned an error: (401) Unauthorized."}

I am very much worried  because i am helpless from the date i submitted my problem to experts exchange. Please help me since i don't know how to proceed further....

Kind regards,
Pooja
0
 
poojasureshkumarAuthor Commented:
Hi ,
I got the solution . Thanks all.

Kind regards,
Pooja
0
 
poojasureshkumarAuthor Commented:
Hi ,
Solution which given by CodeCruiser has given me brief idea about REST services and though it doesn't gave me perfect solution and it gave me useful information to proceed along further and helped me to get the answer on my own. So i would like to grant 100 points to CodeCruiser.
I think remaining 150 points should be leave as it is and i think honestly it is not deserved for anybody.

Kind regards,
Pooja
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

  • 8
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now