Knowledgebase

Search the Rally Knowledgebase to find solutions to your Rally product questions.

This is a public Hive  publicRSS

How To

    Simple Example for getting a REST URL in VB.NET
    How To posted 4/29/09 by Dave Smith , tagged Integrations, Web Services API
    2078 Views
    Title:
    Simple Example for getting a REST URL in VB.NET
    Platform:
    Windows
    Abstract:

    Basic example in VB to do a REST Call

    How To:

    (it's a proof of concept using a vb form with a text box that shows output - you would still need to handle the rss/xml that comes back, but it should work for you in a vb setting)

    Imports System
    Imports System.IO
    Imports System.Net
    Imports System.Text


    Public Class Form1
        Private Sub btntestrest_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btntestrest.Click

             
            addtoText("Starting")

            'Setup the URL to get
            Dim s_rallyurl As String = "https://rally1.rallydev.com:443/slm/webservice/1.10/rss/task?title=Blocked Tasks&query=((Blocked = true) and (State != Completed))&order=Rank"

            'Setup the authenication info

            Dim rallyrequest As WebRequest = WebRequest.Create(s_rallyurl)
            rallyrequest.PreAuthenticate = True
            Dim rallyuser As String = "myuser@company.com"
            Dim rallypass As String = "rallypassword"
            Dim rallycredentials As New NetworkCredential(rallyuser, rallypass)
            rallyrequest.Credentials = rallycredentials

            Dim s_update As String = ""       'make the call
            Dim rallyresponse As HttpWebResponse = CType(rallyrequest.GetResponse(), HttpWebResponse)

            addtoText(rallyresponse.StatusDescription)
            Dim mydatastream As Stream = rallyresponse.GetResponseStream()
            Dim myreader As New StreamReader(mydatastream)
            Dim myanswer As String = myreader.ReadToEnd()
            addtoText(myanswer)
            myreader.Close()
            mydatastream.Close()
            rallyresponse.Close()

            addtoText("closed")
        End Sub

        Private Sub addtoText(ByVal linetoAppend)
            Dim mymessage As String = vbCrLf
            mymessage = mymessage & linetoAppend
            RichTextBox1.AppendText(mymessage)
        End Sub
    End Class