Call client windows service from asp.net - c#

I have an asp.net application that must call a client windows service that will start an exe previouslly installed in the client computer.
I use ServiceController class to manage the service: sc = new ServiceController("HippoTwain", Environment.MachineName);
I call the service using sc.ExecuteCommand((int)HippoTwainMethods.Select);
Then, the service does:
ApplicationLoader.PROCESS_INFORMATION procInfo;
ApplicationLoader.StartProcessAndBypassUAC(#"C:\HippoCard\HTwain\HTwain.exe", out procInfo);
The problem is: The asp.net is calling the Server service, but I need to call the service from the Client computer.
How do I do this?

If you want to access the service installed on the client computer, you obviously have to call it from the client. That means either from a Silverlight control or from javascript.
What I suggest is to make the Windows service host a web service on localhost. Inside this web service add a method that once called starts your process.
On your page add a Silverlight control that calls the above method or make a jquery.post() call to that method. Obviously you need to mind the security issues, but you get the idea: you can't access a resource on the client-side using code executed server-side.

Related

How to call Windows background service in Blazor(.net6) web application?

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.

SessionState Collection item disappearing when called from a desktop client

I've got a legacy ASP.NET soap web service on my computer. The service has this annotation:
[WebMethod(EnableSession = true)]
on several methods and uses the Session property to save some information:
Session[CONSTANT] = some_value;
This value is preserved when I call different methods of the web service one after another in a browser (both Chrome and Internet Explorer) but NOT when I call the service methods from a proxy created in Powershell or in Visual Studio.
Do I have to set some parameters on the client to preserve the Session?
On another computer the same service is installed and there the value stored in the Session is NOT preserved between method calls, not even in the browsers. Do I need then to change some parameters in the web server in this case?
In both cases the web service is hosted in IIS.
The following has done the job for me:
adding a legacy web reference instead of service reference.
using the SoapClient.CookieContainerlike in
Implementing session in SOAP Client

ASP webservice call to be automated

I have an ASP web service call that imports some data.
This is usually invoked by a user on a Silverlight client, clicking a button.
Now they want to have that automated to periodically import.
I know I can set up a windows service to invoke the web service call, but are there any alternatives?
I just made application like that in 2 ways :
1- windows console which will run as batch to call the web service
2- windows service as you have mentiond in your quesion
i have noticed that webservice is more better than batch file as its more stable
Create DispatcherTimer in silverlight Application Put the webService Method in Tick event of DispatcherTimer Object.
Refer this Link for DispatcherTimeclass
http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer%28VS.95%29.aspx

NullReferenceException while calling WebMethod

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.

Calling ASP.net Web Service from C# Application

I have a question. How can i invoke a web service and get the result from a C# desktop application. I am making a desktop app and I want it to be able to connect to my online ASP.net web services. How is this possible?
In Solution Explorer, right-click your project node and select Add Service Reference.
Enter the URL where your service WSDL is located. This is usually the URL of the service itself.
This generates a strongly-typed proxy class in a new Services References folder in your project.
Write code in your desktop app to instantiate the proxy class and invoke methods on it. The rest works like magic. :)
AB Kolan was also correct, but Add Web Reference uses the old-style web services framework whereas Add Service References uses the new WCF stack. Important note: It is not required that the service itself use WCF for you to use WCF on the client side. WCF on the client is typically the best choice for any service, provided you can take a dependency on .NET 3.0 and above.
Add a Web Reference to the webservice in your Desktop App project reference. Doing so would generate a Proxy for the Webservice called Reference.cs
You can access your webservice using the proxy.
This is possible the same way that you access web services from any other type of application, be it an ASP.NET page, a class library or windows service.
For an explanatory tutorial on the subject, see Accessing a Web Service from a Desktop Application.
Will get help how to create a webservice and consume that service:
http://www.c-sharpcorner.com/UploadFile/0c1bb2/consuming-web-service-in-Asp-Net-web-application/
Thanks

Categories

Resources