How do I consume windows background service in my Blazor .net 6 web application.
I have created two projects, one is a background service and it is running on my machine and another is a Blazor web application. So How do I call running windows service in my web application?
Its generally not a good idea to "call a windows service" directly. If you want your background service to respond to web requests it should be hosted in IIS or kestrel, and called like a regular api. This is idea if you expect a response from your request. Otherwise I would suggest using a message broker such as rabbit mq to dispatch a request. Ideally the message would be sent by an endpoint exposed with your blazor app.
Related
I'm creating a net core worker service to periodically fetch and process various data. This will run as a Windows Service on an application server.
In some cases I need to tell the worker to "process data now" and fetch limited information about it's internal workings.
The process communicating with the worker (basically a manager desktop app) and the worker itself will run on the same application server. I can't think of a better way other than turning the worker into an ASP.NET Core WebApi with a hosted service. Such a webapi would only be bound to a localhost address, but how should I secure it so that it's only listening to a requests from my desktop app?
I'd like to avoid certificates so I could keep deployments simple.
To protect web API, you can add authentication. For example, you can use IdentityServer4 to add OAuth with Client Credential flow for your web API, then before you can desktop can call your web API, it need to acquire the token first.
Below are the helpful links for your reference:
Tutorial: Create a web API with ASP.NET Core
Protecting an API using Client Credentials
I created a WCF Service Library, which I host via a Windows Service.
Is it possible to save information across API calls?
I know that if I host the WCF Service Library in IIS with ASP.Net compatibility turned on and making a few modifications to the WCF library that I can use
HttpContext.
HttpContext.Current.Session["name"] = <value>;
WCF started as a Windows Service does not have ASP.Net support to the best of my knowledge, as the library is not hosted by IIS. Is there a way for a WCF library launched via a Windows Service to save information across calls for a specific caller?
I am thinking about writing an application that will monitor IIS Service with iPhone, and send notification, perform resets if an IIS goes down.
I dont want to create a web service to do that but rather connect to a machine, specifying credentials and then get data from the IIS Service state.
Is it even possible?
Is it possible with iPhone?
I need to make this app generic enough for people to use with their hosted web sites and monitor their health and being able to reset it and/or recycle AppPools. I cant implement a service for any hosted environment. I need to be able to give the iPhone users an ability to connect to their host and once you are connected to the machine and authenticated to perform WMIs the phone users can mess with the iis. Is it possible?
I see your point not wanting to use web service because you want to monitor and reset IIS service, while web service is based on IIS. How about RestFul service? I have created RestFul service based on OWIN (Open Web Interface for .Net) and Kayak. Kayak may have some examples there.
The cool thing about those tools or lib is that the framework is very simple and does not rely on IIS. You can provide two URLs, one for get and one for post. The former is to get status of IIS server and post is to reset IIS. Those services can be just XML of JSON based objects and it will be up to the the OWIN service to do the job on the back end. Another great feature of this is that you can even create the service in a console app or any other ways (Windows service or Window Form in system tray) on WindowsXP or Home version. The app will provide RestFul service based on HTTP with specific port.
RestFul service is available for variety of platforms, including iPhone.
Although IIS supports remote administration I doubt there's a way to implement it on the iPhone easily.
You could write an actual Windows Server (not a web service) you could connect to with a socket which can do all the monitoring instead though.
I am create an iPhone app that needs to talk to a Windows C# app. The app will run as either a Service or Form Application.
What would be the best way to accomplish this? Ideally exposing a service-type architecture would be best as I don't need a stateful connection (stateless is fine in this case).
Can a WCF service hosted by my app using a form of TCP binding be consumed by my iPhone? Or can an app host using httpBinding without the aid of IIS or some other web server?
To run WCF on iPhone you need MonoTouch. Currently, which isn't completely implemented.
I don't think it's a good idea.
Web Service are a better idea in my opinion. You can spawn a web service listener from your console/gui/service Windows C# application.
Here's what I ended up doing:
In my .NET windows service, I created WCF service bound using a WebHttpBinding endpoint. Doing so exposed my WCF services as JSON.
From the iPhone, using Objective-C, I used the ASIHTTPRequest and json-framework libraries to talk to and parse the JSON web service exposed by my .net app.
Expose your C# application functionality as a ReSTful web service. More information on exposing WCF service is available here
And there are project templates available for creating REST WCF service. Download the WCF REST starter kit.You can expose your service in XML/JSON format.
Then from your iPhone app, you may consume the web service exposed.
I have the following problem;
My console app is running on the server and all I want to do is control it over ASP.NET Web Service.
I added new ASP.NET Web Service project to my Solution where my main console app and added reference to it.
The problem is every time WebMethod calls function from console app, i get the nullreferenceexception. Even if I try to use static classes or singletons; every object is null, although my console app is running absolutely correctly.
Should I change some permisions setting or something?
Thank you for your time.
Based on your comments - your console app needs to expose API to administer it. Now this can be possible by using WCF Web Services where your console app needs to host the WCF Services. Controlling console app from ASP.NET web services would be difficult because ASP.NET web services would be hosted in different process/AppDomain (by IIS) - so they somehow need to talk console app process. This across process talk is possible in .NET using remoting or WCF. So its better to use directly WCF to provide web based API (instead of using ASP.NET web services).
Refer this article to start with creating simple WCF service and hosting it in console.