Azure-functions-host: Visual Basic .NET support

Created on 3 Apr 2017  路  9Comments  路  Source: Azure/azure-functions-host

Please provide a succinct description of the issue.

I think there is great value to add Visual Basic support to Azure Functions.

Most helpful comment

https://twitter.com/johnnliu/status/849643313942609920

Oh we are going to have a lot of fun.

Imports System.Net
Imports System.Net.Http
Imports System.Threading.Tasks
Imports System.Runtime.CompilerServices
Imports System.Web.Script.Serialization

Public Class MyFunction

Public Shared Async Function Run(ByVal req As HttpRequestMessage) As Task(Of HttpResponseMessage)

    'parse query parameter

    'Dim name = req.GetQueryNameValuePairs()
    '.FirstOrDefault(q >= String.Compare(q.Key, "name", True) == 0)
    '.Value;

    'Get request body
    Dim Data As String = Await req.Content.ReadAsStringAsync()

    'Set name to query string Or body data
    Dim json As Dictionary(Of String, Object) = New JavaScriptSerializer().Deserialize(Of Object)(Data)
    Dim name = json.Item("name")

    Dim response As HttpResponseMessage = New HttpResponseMessage()

    If name Is Nothing Then
        response.StatusCode = HttpStatusCode.BadRequest
        response.Content = New StringContent("Please pass a name on the query string or in the request body")
    Else
        response.StatusCode = HttpStatusCode.OK
        response.Content = New StringContent("Hello " & name)
    End If
    Return response
End Function

End Class

All 9 comments

We should be able to support this via the precompiled approach. We are missing docs/etc. for "full support", but it should just work today.

hmm I might have a weekend project now.

@johnnliu I've reached out to Anthony Green (I know him quite well), and he'll see if there are ways that the VB team can partner with us on this.

You should indeed use the precompiled approach, outlined in https://aka.ms/precompiled-functions.

https://twitter.com/johnnliu/status/849643313942609920

Oh we are going to have a lot of fun.

Imports System.Net
Imports System.Net.Http
Imports System.Threading.Tasks
Imports System.Runtime.CompilerServices
Imports System.Web.Script.Serialization

Public Class MyFunction

Public Shared Async Function Run(ByVal req As HttpRequestMessage) As Task(Of HttpResponseMessage)

    'parse query parameter

    'Dim name = req.GetQueryNameValuePairs()
    '.FirstOrDefault(q >= String.Compare(q.Key, "name", True) == 0)
    '.Value;

    'Get request body
    Dim Data As String = Await req.Content.ReadAsStringAsync()

    'Set name to query string Or body data
    Dim json As Dictionary(Of String, Object) = New JavaScriptSerializer().Deserialize(Of Object)(Data)
    Dim name = json.Item("name")

    Dim response As HttpResponseMessage = New HttpResponseMessage()

    If name Is Nothing Then
        response.StatusCode = HttpStatusCode.BadRequest
        response.Content = New StringContent("Please pass a name on the query string or in the request body")
    Else
        response.StatusCode = HttpStatusCode.OK
        response.Content = New StringContent("Hello " & name)
    End If
    Return response
End Function

End Class

Can we tell VBTeam that HttpRequestMessageExtensions don't work and it's really hard to do things like req.GetQueryNameValuePairs() from query string...

Also, VB really should have JSON literals like they have XML literals...

image

solution structure.

@johnnliu,

I'm not saying that we _should_ have JSON literals. Just that I have an implemented prototype of JSON literals in my fork of Roslyn that I'd love some user feedback on... shhh, don't tell anyone ;)

I'm going to move this issue into the backlog, as the main work to do here is to create samples and documentation. I'll work with @AnthonyDGreen to partner on this.

This is supported with the pre-compiled model. Documentation applies, but we don't currently plan on providing samples and templates.

Was this page helpful?
0 / 5 - 0 ratings