Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to create an Array of Azure parameter function, but it's not working for me. For these, I tried below code.

What I have tried:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FunctionApp4
{

    public class ALCBarCodes
    {

        public string BarCodeText { get; set; }
        public string BarCodeWidth { get; set; }
        public string BarCodeHeight { get; set; }
        public string BarCodeType { get; set; }
        public string BarCodeFont { get; set; }

    }

}


Azure Function


C#
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;

namespace FunctionApp4
{
    public static class Function4
    {
        [FunctionName("Function4")]
        public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "Function4/{ALCBarCodes}")]HttpRequestMessage req, List<ALCBarCodes> list, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            // Fetching the name from the path parameter in the request URL
            return req.CreateResponse(HttpStatusCode.OK, list);
        }
    }
}


On this case how can I request the URL?

I tried below URL but it's not working.

http://localhost:7071/api/Function4/1

Any help on this?
Posted
Updated 13-Mar-19 20:10pm
v2
Comments
Afzaal Ahmad Zeeshan 12-Mar-19 10:06am    
You do not have any argument with the name of ALCBarCodes, instead this is the type for the argument list. This also is a type of List, I would recommend using POST method to send a list.

Secondly, what are the bindings for this Azure Function? Also, what does your Azure Functions SDK show in the terminal?
Bojjaiah 13-Mar-19 0:44am    
I am a newbie. If possible give me any examples or reference links related to the above thread? It will help.

1 solution

Finally worked below code.

C#
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
using Newtonsoft.Json;

namespace Forum
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task<HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)]
            HttpRequestMessage req,
            TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            //dynamic input =await req.Content.ReadAsAsync<dynamic>();

            ALCBarCodes[] input = await req.Content.ReadAsAsync<ALCBarCodes[]>();

            // Fetching the name from the path parameter in the request URL
            return req.CreateResponse(HttpStatusCode.OK, input);
        }
    }
    public class ALCBarCodes
    {
        public string BarCodeText { get; set; }
        public string BarCodeWidth { get; set; }
        public string BarCodeHeight { get; set; }
        public string BarCodeType { get; set; }
        public string BarCodeFont { get; set; }
    }
}


Sample input:

JSON
[
{
"BarCodeText": "1234",
"BarCodeWidth": "90",
"BarCodeHeight": "1234",
"BarCodeType": "128",
"BarCodeFont": "12"
},
{
"BarCodeText": "1234",
"BarCodeWidth": "90",
"BarCodeHeight": "1234",
"BarCodeType": "128",
"BarCodeFont": "12"
},
{
"BarCodeText": "1234",
"BarCodeWidth": "90",
"BarCodeHeight": "1234",
"BarCodeType": "128",
"BarCodeFont": "12"
}
]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900