none
Can webservices using JSON be called easily from vb.net web application RRS feed

  • Question

  • Hi All,

    I have a VB . Net web application and I need to call a webservice for my data. The webservice is hosted on a separate environment and created by another team. They are  asking us to consume is through JSON and not SOAP. Will that be an issue for my application? Do I need to do more coding in that case because I have worked with SOAP before and its very straight forward. But I have never used JSON.

    Any help will be highly appreciated.

    Thanks,

    Srikant Mishra


    Srikant Mishra

    Thursday, June 29, 2017 2:31 PM

All replies

  • I would recommend posting your question to one of the ASP.NET forums:

    https://forums.asp.net/


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Thursday, June 29, 2017 3:01 PM
  • Calling a webservice is easy.  Are you calling a web address?  If so the following will outline how to get json into your app in usable format.

    1.  Using your app go to the call of the webservice and run it to get the json (it is just text).

    2.  Set a watch on the variable that you now have the json in.  Using the down arrow to view the value choose JSON Visualizer and you will see the data in a formatted display.  That is just to ensure that you are getting what you want.

    3.  Now view the same data as text (Text Visualizer) and copy the retrieved json.

    4.  Close the app.

    5.   Create a new class file in VS, the name doesn't matter as it won't be used.  Clear out the code created by VS and now go to the Edit menu item and selected Paste Special/ Paste Json as Classes.  This will provide you with the class structure corresponding to the json.

    6.  The following piece of code shows how to use NewtonSoft to read the Json in to the class(es) you created above.

        Public Shared Function GetMDBConfiguration() As DBConfiguration
            Dim client = New RestClient("https://api.themoviedb.org/3/configuration?api_key=MYAPIKEY")
            Dim request = New RestRequest(Method.[GET])
            request.AddParameter("undefined", "{}", ParameterType.RequestBody)
            Dim response As IRestResponse = client.Execute(request)
    
            Dim json As String = response.Content
            Dim ser As JObject = JObject.Parse(json)
            Dim data As List(Of JToken) = ser.Children().ToList
            Dim output As String = ""
            Dim config = JsonConvert.DeserializeObject(Of DBConfiguration)(json)
            Return config
        End Function

    You should now have classes filled with the data from the web service call.

    Hope this helps


    Lloyd Sheen


    • Edited by sqlguy Thursday, June 29, 2017 10:30 PM
    • Proposed as answer by Reed KimbleMVP Friday, June 30, 2017 1:17 PM
    Thursday, June 29, 2017 10:18 PM
  • Hi SrikantMishra,

    Since this forum is discussing and asking questions about the Visual Basic programming language,
    IDE, libraries, samples, and tools, and your issue is more related to asp.net. This link about asp.net, please refer that: https://forums.asp.net/

    Thank you for participating in the forum activities.

    Best Regards,

    Cherry



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 30, 2017 7:31 AM
  • You will probably want to look at Web API.  The following example is in C#, but you should be able to get the general idea of consuming the web api from your ASP web app.

    https://docs.microsoft.com/en-us/aspnet/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Friday, June 30, 2017 1:16 PM
  • Just a quick note to mention that there are other ways to consume the JSON - depending on the complexity of the response objects, the NewtonSoft solution may be overkill... you don't always need the strongly-typed object model.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Friday, June 30, 2017 1:20 PM
  • I have a VB . Net web application and I need to call a webservice for my data. The webservice is hosted on a separate environment and created by another team.

    The who you should be directing all questions to is this other team.

    Friday, June 30, 2017 3:00 PM