#difference between .net vs csharp
Explore tagged Tumblr posts
Link
Microsoft Asp.Net is a web development framework that’s used to build web pages, web services & web applications. It is a part of the .net framework. Asp.Net also supports basic.Net, C#, Jscript .Net and open-source languages like Python and Perl. Additionally, the .Net developer tool can be used to create an application for Windows operating systems and for .net web development.
#asp.net vs c#dot net vs c#difference between asp.net vs c#difference between .net vs c#asp.net vs csharp#dot net vs csharp#difference between asp.net vs csharp#difference between .net vs csharp
0 notes
Text
Multiple output in Azure Functions with C#
In this post I like to analyse how to return multiple output in Azure Functions with C# and Service Bus. If you want more info, in the last week or so, I published some posts about Azure Function in C# or F# like “Create Azure Function in C# Script and Service Bus” or “Creating Azure Function in F#“.
You have a platform on Azure and two different services are triggered by a message from Service Bus. At some point, you have an Azure Function doing a procedure that has to do 3 outputs:
response an ActionResult like OkObjectResult to allow the UI to continue its activity
send a message to a Service Bus to trigger another process
and also send another message to another Service Bus to trigger a different process
In the Microsoft documentation, Azure Service Bus output binding for Azure Functions, there is only one output, usually to Service Bus and the code Microsoft offers is pretty easy:
[FunctionName("ServiceBusOutput")] [return: ServiceBus("myqueue", Connection = "ServiceBusConnection")] public static string ServiceBusOutput([HttpTrigger] dynamic input, ILogger log) { log.LogInformation($"C# function processed: {input.Text}"); return input.Text; }
This function is triggered from an HttpRequest and return (see the annotation return:) a message in Service Bus with input.Text. This is the base function I will use.
Setup a Service Bus
In the Azure Portal, I’m going to create a new Service Bus. I’m calling it aztest.
Create Service Bus in Azure Portal
After that, I create two new queues: message-out1 and message-out2. Click on + Queue in the portal and type the name of the queue. Then press Create to create each queue.
Create a new queue in Azure Service Bus
Later in the project I need to connection string to this Service Bus: in the menu on the left, select Shared access policies, then click on RootManageSharedAccessKey and save the Primary Connection String.
Copy the connection string for the Service Bus
For now, I’m done with Service Bus and the Azure Portal.
Create a new project with Visual Studio
Open Visual Studio and Create a new project.From the list, select Azure Functions and press Next.
Create a new project with Visual Studio
Configure your new project: I decide to call it AFMultiOutput (Azure Functions Multiple Output). Press on Create.
Configure your new project
In the next window of the creating wizard, I choose Azure Functions v3 (.NET Core) and Http Trigger as trigger of the function. Then press Create.
Create a new Azure Functions Application
Done! Now, I have to add a package to connect Service Bus. Right click on the project in the Solution Explorer and click on Manage NuGet Packages…
Add NuGet for connecting Service Bus
Now, search and install Microsoft.Azure.WebJobs.Extensions.ServiceBus
NuGet packages to install Service Bus
I have to add the connection strings for Service Bus. For that, in the local.settings.json I add two new keys called ServiceBusConnectionString1 and ServiceBusConnectionString1. Replace <connection1> and <connection2> with the Primary Connection String from the Azure Portal. Be careful with the name of those keys.
{ "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "FUNCTIONS_WORKER_RUNTIME": "dotnet", "ServiceBusConnectionString1": "<connection1>", "ServiceBusConnectionString2": "<connection2>" } }
Next step is to add in the signature of the function our output. As I said, I want two outputs, one for each Service Bus. The new signature is that:
public async Task<IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, [ServiceBus("message-out1", Connection = "ServiceBusConnectionString1")] IAsyncCollector<dynamic> outputServiceBus1, [ServiceBus("message-out2", Connection = "ServiceBusConnectionString2")] IAsyncCollector<dynamic> outputServiceBus2, ILogger log)
Automatically, the Azure Function will read the settings to grab the connection strings. Notice the first parameter after ServiceBus is the name of the queue.
To write multiple values to an output binding, or if a successful function invocation might not result in anything to pass to the output binding, use the ICollector or IAsyncCollector types. These types are write-only collections that are written to the output binding when the method completes.
As outputs of this function, I use those variables and add a simple message in each queue.
await outputServiceBus1.AddAsync("Item1"); await outputServiceBus2.AddAsync("Item2");
Finally, I have to return an HttpCode to the caller. It is easy to reply with an object, in this case a null object.
return new OkObjectResult(null);
The multiple output in Azure Functions with C# is done and looks like that:
public class Function1 { [FunctionName("Function1")] public async Task<IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, [ServiceBus("message-out1", Connection = "ServiceBusConnectionString1")] IAsyncCollector<dynamic> outputServiceBus1, [ServiceBus("message-out2", Connection = "ServiceBusConnectionString2")] IAsyncCollector<dynamic> outputServiceBus2, ILogger log) { await outputServiceBus1.AddAsync("Item1"); await outputServiceBus2.AddAsync("Item2"); return new OkObjectResult(null); } }
Explore your Service Bus
To explore this brand-new Service Bus, I download Service Bus Explorer from Github, a really good project. If you don’t want to source code, the installer is here.
Service Bus Explorer
After that, I have to connect Service Bus Explorer with the Service Bus. For the Service Bus page, on the left, there is an option called “Shared access policies“: click there and click on “RootManageSharedAccessKey“. Now, copy the “Primary Connection String“ or copy the keys from your local.settings.json
Copy the connection string for the Service Bus
Then, in Service Bus Explore, click on File > Connect. Paste the “Primary Connection String” in the connection string textbox and then press Ok.
Service Bus Explorer: connect
Finally, I find my queues and I browse them.
Service Bus Explorer with my queues
Run the function
It is time to run the function and verify if it is working as I want. Run the project in Visual Studio.
Azure Function is running
Open a browser and insert the url for the function, in my case is
http://localhost:7071/api/Function1
In the window, I see the function sent some output without errors.
The function replied to my request without errors
So, in Service Bus Explorer, I refreshed the queue with F5. Now I see the messages in both queues.
Messages in both queues
ICollector<T> vs IAsyncCollector<T>
So, what is the difference between ICollector<T> and IAsyncCollector<T>?
ICollector<T>.Add(item) will always perform the add operation against the underlying service immediately. E.g. the implementation for the Queue binding will enqueue messages immediately as they are added.
IAsyncCollector<T>.AddAsync(item) behavior varies from binding to binding, based on whether the underlying service supports batching. In such cases, AddAsync may only actually save the added items to be flushed later by the corresponding IAsyncCollector<T>.FlushAsync method. When a function completes successfully FlushAsync will be called automatically. You can allow the auto-flush behavior to flush for you, or you may choose to call FlushAsync manually in your function as you need to.
Conclusion
Finally, I have my multiple output in Azure Functions with C# and Service Bus. Not really difficult but a bit long. If you have any questions, please use our forum.
If you want to take a look at my code, visit my repository on Github.
The post Multiple output in Azure Functions with C# appeared first on PureSourceCode.
from WordPress https://www.puresourcecode.com/dotnet/csharp/multiple-output-in-azure-functions-with-c/
0 notes
Link
Owin & Katana An Overview of Project Katana | Microsoft Docs Understanding OWIN and Katana - CodeProject Data Access ASP.NET Data Access - Recommended Resources | Microsoft Docs async and parallel programming with .NET 4+ (TPL) String Modifying http://stackoverflow.com/questions/444798/case-insensitive-containsstring Entity Framework c# - Dynamic filtering and sorting with Entity Framework entity framework - Code-first vs Model/Database-first Entity Framework Code-Based Configuration (EF6 onwards) Performance Improving http://stackoverflow.com/questions/30816496/why-do-local-variables-require-initialization-but-fields-do-not c# - Will using 'var' affect performance? http://blog.slaks.net/2015-01-12/linq-count-considered-occasionally-harmful Miscellaneous: (will clean up later)
https://msdn.microsoft.com/en-us/library/bb964711.aspx?f=255&MSPPError=-2147217396
concepts
https://stackoverflow.com/questions/2220134/displaying-a-pdf-file-from-winform
https://stackoverflow.com/questions/4596300/where-exactly-is-the-difference-between-ioc-and-di
https://www.mikesdotnetting.com/article/128/get-the-drop-on-asp-net-mvc-dropdownlists
http://digitaldrummerj.me/iis-express-windows-authentication/
http://codebetter.com/brendantompkins/2004/05/13/run-a-bat-file-from-asp-net/
https://weblogs.asp.net/scottgu/asp-net-mvc-3-and-the-helper-syntax-within-razor
https://www.codeproject.com/Articles/703634/SOLID-architecture-principles-using-simple-Csharp
https://stackoverflow.com/questions/982677/visual-studio-command-to-collapse-all-sections-of-code
http://stackoverflow.com/questions/6209125/asp-net-mvc3-debug-and-release-app-settings-not-working
http://stackoverflow.com/questions/9238953/how-to-empty-recyclebin-through-command-prompt
http://stackoverflow.com/questions/32813149/can-mono-run-windows-universal-apps
https://dusted.codes/understanding-aspnet-core-10-aka-aspnet-5-and-why-it-will-replace-classic-aspnet
http://stephenwalther.com/archive/2015/02/24/top-10-changes-in-asp-net-5-and-mvc-6
http://blogs.msdn.com/b/prashant_upadhyay/archive/2012/10/19/upgrading-target-framework-from-4-0-to-4-5-for-asp-net-mvc-applications.aspx
http://msdn.microsoft.com/en-us/library/system.threading.tasks.task.aspx
https://msdn.microsoft.com/en-us/library/bb964711.aspx?f=255&MSPPError=-2147217396
http://msdn.microsoft.com/en-us/library/ms178586.aspx
http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicebase.onstop.aspx
http://msdn.microsoft.com/en-us/library/vstudio/88c54tsw.aspx
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.waitforexit.aspx
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx
http://msdn.microsoft.com/en-us/library/ms973839.aspx
http://msdn.microsoft.com/en-us/library/ee332485.aspx
http://msdn.microsoft.com/en-us/library/ms178581(VS.100).aspx
http://msdn.microsoft.com/en-us/library/75x4ha6s.aspx
http://msdn.microsoft.com/en-us/library/ms178594.ASPX
http://msdn.microsoft.com/en-us/library/2y3fs9xs.aspx
https://msdn.microsoft.com/en-us/magazine/dn802603.aspx
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute.aspx
http://msdn.microsoft.com/en-us/library/zhhddkxy(v=vs.100).aspx
http://geekswithblogs.net/WTFNext/archive/2013/05/29/exam-70-486-study-material-developing-asp.net-mvc-4-web-applications.aspx
http://msdn.microsoft.com/en-us/library/ms247246.aspx
http://msdn.microsoft.com/en-us/library/system.net.http.httpmethod.aspx
http://aspnetmvc.readthedocs.org/projects/mvc/en/latest/views/tag-helpers/intro.html
https://github.com/aspnet/Announcements/issues/194
http://en.wikipedia.org/wiki/Resource_Description_Framework
http://en.wikipedia.org/wiki/Remote_Desktop_Protocol
http://weblogs.asp.net/scottgu/asp-net-mvc-3-layouts-and-sections-with-razor
http://msdn.microsoft.com/en-us/library/system.web.mvc.validateantiforgerytokenattribute(v=vs.108).aspx
http://stackoverflow.com/questions/477124/what-does-asp-net-mean
http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironment.ASPX
http://www.asp.net/web-forms/overview/data-access/introduction/creating-a-data-access-layer-cs
http://stackoverflow.com/questions/30816496/why-do-local-variables-require-initialization-but-fields-do-not?utm_medium=social&utm_source=facebook.com&utm_campaign=so-facebook
http://www.codeproject.com/Articles/41726/Peer-to-Peer-ASP-NET-State-Server
http://odetocode.com/Blogs/scott/archive/2009/07/16/resource-files-and-asp-net-mvc-projects.aspx
http://todomvc.com/examples/typescript-react/#/
http://stackoverflow.com/questions/2714288/pros-and-cons-of-using-asp-net-session-state-server-instead-of-inproc
http://i3.asp.net/media/4773381/lifecycle-of-an-aspnet-mvc-5-application.pdf?version_id=&cdn_id=2012-10-31-001
http://stackoverflow.com/questions/35701953/why-cant-gettype-find-types-when-invoked-through-a-method-group-delegate
http://andymaleh.blogspot.com/2011/10/decoupling-views-from-controllers-in.html
https://blog.xamarin.com/getting-started-azure-mobile-apps-easy-tables/?utm_medium=social&utm_campaign=blog&utm_source=linkedin&utm_content=azure-easy-tables
http://stackoverflow.com/questions/7027683/html-raw-in-asp-net-mvc-razor-view
http://stackoverflow.com/questions/662773/returning-in-the-middle-of-a-using-block
https://en.wikipedia.org/wiki/SOLID_(object-oriented_design)
http://stackoverflow.com/questions/10441879/daisy-chain-methods-in-c-sharp
http://www.generative-gestaltung.de/
Reserve DLL I've never had the time to do this because its always been worth more of my time to just recreate the application but someday I would like to try this.
Anti-Reflector .NET Code Protection
0 notes