configuration Error in running Azure function app - azure

Function app unable to run with null configuration error
Developed function in visual studio to read api response.
It works fine when run locally, but doesnt work when publish as azure function app
Below is my entry function which is run on incoming http request:
public static async Task<Bolean> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
expected to run fine.. error instead
The request does not have an associated configuration object or the provided configuration was null.

I had a similar issue. Posting this solution in case it helps anyone.
I added a vanilla Azure Function App project in Visual Studio and while it worked on my local machine, I kept receiving a 500 Internal Server error from the deployed Azure version.
The error response was the same when calling the Function using Postman OR when using the Code + Test section while POSTing a valid request body.
The associated Application Insights trace revealed the error details as:
The solution that worked for me was changing the Runtime version (your Function App > Configuration > Function runtime settings > Runtime version) from the current default value of ~3 to ~1.
Changing this value triggered a restart of the Service within Azure and the 500 internal server error was resolved.
This How to target Azure Functions runtime versions learn.microsoft.com link has further details around this setting.

System.InvalidOperationException: The request does not have an associated configuration object or the provided configuration was null.
When testing the request out side of a httpserver you need to give the request a HttpConfiguration.
To fix this we need to add a HttpConfiguration object through the Properties dictionary as below:
var configuration = new HttpConfiguration();
var request = new System.Net.Http.HttpRequestMessage();
req.Properties[System.Web.Http.Hosting.HttpPropertyKeys.HttpConfigurationKey] = configuration;
For more details, you could refer to https://stackoverflow.com/a/44447349/

Related

Blazor WASM Azure Static Web App, Functions not working

I created a simple Blazor WASM webapp using C# .NET5. It connects to some Functions which in turn get some data from a SQL Server database.
I followed the tutorial of BlazorTrain: https://www.youtube.com/watch?v=5QctDo9MWps
Locally using Azurite to emulate the Azure stuff it all works fine.
But after deployment using GitHub Action the webapp starts but then it needs to get some data using the Functions and that fails. Running the Function in Postman results in a 503: Function host is not running.
I'm not sure what I need to configure more. I can't find the logging from Functions. I use the injected ILog, but can find the log messages in Azure Portal.
In Azure portal I see my 3 GET functions, but no option to test or see the logging.
With the help of #Aravid I found my problem.
Because I locally needed to tell my client the URL of the API I added a configuration in Client\wwwroot\appsettings.Development.json.
Of course this file doesn't get deployed.
After changing my code in Program.cs to:
var apiAddress = builder.Configuration["ApiAddress"] ?? $"{builder.HostEnvironment.BaseAddress}/api/";
builder.Services.AddHttpClient("Api",(options) => {
options.BaseAddress = new Uri(apiAddress);
});
My client works again.
I also added my SqlServer connection string in the Application Settings of my Static Web App and the functions are working as well.
I hope somebody else will benefit from this. Took me several hours to figure it out ;)

local development azure functions 'HttpRequestMessage' does not contain a definition for 'GetQueryNameValuePairs'

I am having trouble running an azure function locally that works in the portal. I created a default C# Http trigger in Azure, then download the app content to run locally.
[5/22/18 9:03:21 PM] run.csx(8,23): error CS1061: 'HttpRequestMessage' does not contain a definition for 'GetQueryNameValuePairs' and no extension method 'GetQueryNameValuePairs' accepting a first argument of type 'HttpRequestMessage' could be found (are you missing a using directive or an assembly reference?)
[5/22/18 9:03:21 PM] run.csx(20,15): error CS1501: No overload for method 'CreateResponse' takes 2 arguments
The function works perfectly in the portal.
As #Mikhail has said, it's caused by the wrong functions core tools(CLI) version. The code you download works with v1 CLI(.Net Framework) while v2(you may have installed) is on .NET Core.
To install required CLI, follow CLI installation. If local OS(like MacOS) doesn't support v1 CLI we may turn to v2 CLI which can run cross-platform. With v2 CLI, v1 code created on portal can't be used, hence we need to create functions locally or change portal function app runtime to ~2 then create and download again.
Note that before we change the runtime, function app should be empty because functions created before depend on different runtime and usually will become invalid after the change.
To give a specific example of code that does work, the below would work in Functions v2:
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post",
Route = null)] HttpRequest req, ILogger log)
{
int id;
bool parsedId = int.TryParse(req.Query["id"], out id);
...
}

Swagger not working on Azure Web app running as OWIN

I have a ASP.NET Web API implemented as OWIN middleware. I hosted it on azure and now I have a problem using swagger. It is perfectly working on localhost but when I try it on azure I get this:
The way I did my configuration for swagger on the API was to completely remove SwaggerConfig.cs file and add all the configuration into my Startup.cs class as shown here: How to generate documentation using swashbuckle for WebApi 2 with Owin . If it is going to help, I am trying to implement oAuth2 between my API, identity server and client application.
Can you help me find out what is the reason for not getting swagger functionality on Azure?
EDIT: I also tried the solution from here but without success. I went to my API->Properties->Buld tab->Changed to 'Release' configuration->In the output path added the same what was in the 'Debug' configuration and nothing.
My bin folder on Azure:
I had this problem myself when going though this tutorial.
In that tutorial on #3 under "Configure the middle tier to call the data tier" I named my key apiAppURL instead of toDoListDataAPIURL. This caused me to get 500 response codes and
{
"Message": "An error has occurred."
}
in the response body.
I fixed it by updating the following line:
var client = new ApiApp(new Uri(ConfigurationManager.AppSettings["toDoListApiURL"]));
to
var client = new ApiApp(new Uri(ConfigurationManager.AppSettings["apiAppURL"]));
**The change made was to the string at the end of the line. That code can be found in ToDoListController.cs on line 42
Hope this helps someone!
Check your SwaggerConfig.cs file, if you are not included the xml file with your swagger, it works in your azure app services.
c.IncludeXmlComments($#"{System.AppDomain.CurrentDomain.BaseDirectory}\bin\WebApiSwagger.XML");
c.DescribeAllEnumsAsStrings();
I've included these 2 lines of code to show my xml in the swagger, the azure swagger will gone error.
This is late reply but may help someone in future.
I solved this issue this way:
Set XML documentation file path in project settings to : wwwroot\api.xml
Let Swagger know where the file is within ConfigureServices method in
Startup.cs:
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
// Set the comments path for the Swagger JSON and UI.
var xmlFile = "api.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, "wwwroot", xmlFile);
c.IncludeXmlComments(xmlPath);
});
You can set different paths but you will get the idea of how to do it from this example.

Just created Azure Mobile App service calls return http 400 error

Here's what I'm doing.
Install latest Azure SDK (by the date)
Open Visual Studio 2013
Create a new Azure Mobile App project. The simple service is created with TodoItem DataObject and 2 simple controllers - TodoItemController and ValuesController
Do not change anything
Start the project
The service is started and hosted in local IISExpress on url http://localhost:50993/ (the port may vary).
The "This mobile app is up and running" web page is opened in the browser. But http 400 error is returned when I try to invoke some GET-actions: for example http://localhost:50993/api/values or http://localhost:50993/tables/TodoItem.
Any ideas? Is something wrong in my environment or is that me doing something wrong?
Thanks.
I guess you can opt out of version checking by setting a value of true for the app setting MS_SkipVersionCheck. Specify this either in your web.config or in the Application Settings section of the Azure Portal.
This generally happens when you don't add a ZUMO-API-VERSION header to the request. This is required when making requests from a REST client, but the mobile client SDKs add the header automatically.
To fix, add the header ZUMO-API-VERSION with value of 2.0.0.
To learn more, see https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-client-and-server-versioning/.
Adding
http://localhost:50993/tables/Location?ZUMO-API-VERSION=2.0.0
at the end will do the trick.

Create WCF client programmatically

I have a website with a Silverlight-enabled WCF service. The service works fine, and I can browse to the WSDL page in the browser with no problems.
Now, I am trying to create a client in a DLL. I need to create the whole client programmatically though, because it is being called in a DLL, which for whatever reason (by design?) won't read the ServiceModel section from its own config file.
So here is my code:
Dim endp As EndpointAddress = New EndpointAddress("http://www.mydomain.com/licensing/lic.svc")
Dim bind As WSHttpBinding = New WSHttpBinding()
Dim svc = New lnt.licClient(bind, endp)
Dim rsp = svc.CheckIt(key)
But when i call the svc.CheckIt method, i get the following error:
Content Type application/soap+xml; charset=utf-8 was not supported by service http://www.mydomain.com/licensing/lic.svc.
The client and service bindings may be mismatched.
{"The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'application/soap+msbin1'.."}
How do I properly create my client so that these are properly "matched"??
Thanks in advance!!!
Ah --- found it. The ServiceModel section in the website's web.config was set to customBinding. Changed it so it matched what the client was sending, and now it works beautifully.
I ran into this same issue. More spefically my fix was to update the type of bindings I was using. I was using wsHttpBindings instead of basicHttpBindings. This was causing failures as wsHttpBindings uses SOAP 1.2 while basicHttpBindings use SOAP 1.1 and the service I was using required SOAP 1.1
I had the same error. Service was compiling, client aplication too. Service reference in client aplication was updating reference succesfully. I've tried deleting and add reference once again and it was'nt helpfull. The problem was in removed interface in web service.

Resources