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
Related
So I was thinking instead of the traditional model:
Create a service
Inject the DBContext in the service
Create a controller, inject the service in the controller
Call the controller method to access the data from the razor component
Since you can inject the service directly in the razor component, why not do that and handle the authorization directly in the service?
Would that cause security issues?
Would it be possible to extract the connection string if the code gets debugged via the browser?
In Razor Components there are two modes of execution: On the client browser (Blazor), and on the server (previously called server-side Blazor). When your app is hosted on the client browser, you can presently access your database only through AJAX; that is HttpClient, which requires you to create a web API project that can access your database (directly or through services and repositories, etc.) and returns required data.
As you can see, though the front end Blazor app is running on the client (C# on the client), you cannot access your database directly as your database resides on the server. Authentication can only be and should be employed on the server, and requires AJAX calls.
When your app is hosted on the server (ASP.NET Core application only), you may employ to methods to access your database. Creating a service that query the database and returns data directly to the calling Components App. This is possible because the Components App project, and the hosting ASP.NET Core application resides on the server. No need for Web API here... However, you can create a Web API which serves the data even in this case. Authentication and Authorization should be the same as in traditional ASP.NET Core Web application.
ASP.NET team has stated that switching from client side Blazor to server side Blazor should be done by modifying a couple of code lines. This is partially true, and can be misleading. You have to design your app from the very beginning based on the mode of execution you expect to use. Personally, I would recommend using Web API in both execution models. So that switching from one mode to another can be as easy as ASP.NET team says. Again, if you create a service that directly accesses your database and returns data to the calling Components App, you cannot run this code in browser mode of execution, as the database is on the server and your service "is running" on the client. So designing your applications and knowing before hand how and where it should be used is of great importance. I'm of the opinion that services instead of Web API should only be used in Intranet applications.
Hope this helps...
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.
I've followed the advice in various places, including other questions posted on stackoverflow about sharing the session state between a WCF service and an ASP.NET website, but cannot get my specific scenario to work:
The website and WCF service are both virtual directories of the same application in IIS 7 and both share an app pool. The website stores some data into the session. A flash object rendered on the client makes a call to the WCF service. I would like the WCF service to be able to access the data in the session.
I have put the [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] attribute on the service class, and I have the following lines in the web.config for the service:
and on the binding I have allowCookies="true".
All server side code is written in C#.
However, when using HttpContext.Current.Session from the WCF service, I find that there are no keys stored in the session object.
I have checked with Fiddler, and the flash object definitely passes through the ASP.NET_SessionId with the same value as requests to the website from the browser use.
Can anyone shed any light onto how I can make this scenario work?
Thanks.
Check this:
http://msdn.microsoft.com/en-us/library/ms731193.aspx
In a fairly standard fashion, I created a Web Reference to a SOAP service in Jira for an extension that I'm building (Jira is an issue tracker for those unfamiliar with it). Visual Studio auto-generates a .Settings file and an app.config that contains the web service URL.
Since I'm developing an extension/plugin to an ALM product we're building, the consumer of the extension will be the one who ultimately decides where this web service points to, because it will be integrated with the consumer's instance of Jira. Assume that the web service URL would be stored and pulled from a database.
How can I get the auto-generated service to use a URL from a database instead of from the generated app.config?
Note: we are using v2.0 of the framework, so WCF is not an option.
Even in the 2.0 web service you should be able to change the "Url" property of your web service proxy to the value you desire.
Use the constructor of the client that admits the uri.
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