When to use a page method versus creating a web service? - asmx

Our team is trying to figure out some guidelines for using pagemethods vs. creating an actual asmx web service. Seems to me that pagemethods are primarily for one off type calls that are specific to the page, where as asmx are intended are intended represents more of a reusable set of operations and services. Does this sound correct?

Yes. If yo intend to have something thats going to be used by multiple application it is wise to create it as a separate service, so you are not repeating code between applications and also if have to change you change in a single place.
Simple example,
If you have lets say a authentication need, and you have 2 app, one web and one windows.
If the user base is going to be the same, it does not make sense to go in the Web App create an authentication code/page, the go to you windows app, and do the same all over again. The reason is, what if have to change the hash code for exemple, you would have to go to the web change it, then go to windows change it, and also redeploy window, now
if you have a service, you go to the service change it, and everything now works with the new model, and a big plus, you don't have to redeploy the windows app.
Thats all folks...

Even if you're only working on one page and the functionality in question is only used on that one page, sometimes it's better to move the functionality to a separate web service for performance. i recently worked on a page that would make hundreds of calls to a single page method. i noticed a huge increase in performance when i moved it off to a web service simply because you're not dealing with the entire lifecycle of the page. if you're doing something small though, use page methods to keep everything simple.
Update: ArmedMonkey is correct and page methods do NOT go through the page life cycle.

Related

VB application invoking & directing requests to web browser

We've an existing application developed in VB 6. There are 6 - 8 modules available. In main screen, a separate button is available for each module, which on click will load the respective modules. We're in the process of migrating this to a web-enabled system and identified to go with Java-based solution.
Now instead of completely developing and migrating to Java platform, we're doing a technical feasibility study of migrating module-wise. That is, on click of 'Module 1', for example, will open up a browser instead of existing VB application forms and all subsequent handling/processing/loading/saving will be handled by the web-based Java application, which actually runs on a web/app server. Slowly this will be migrated for other modules also.
My question is, is this technically possible/feasible? That is, can we open up a browser on click of a button and direct all subsequent requests, sessions, cookies to the Java application running on web/app server. Any pointers/suggestions/thoughts towards this are really appreciated.
NOTE: I heard about WinINet API from my friends which enables to interact with HTTP protocols.
If you are moving to the "poor client" (Web) model then your back end will be creating 100% of the user interface as Web pages.
In such a case your existing rich client needs to be dumbed down. There is no point in trying to request the HTML from the server and reinterpreting it into a rich user interface written in VB6.
Thus you don't need to worry about the WinInet API (which you wouldn't need anyway since from Win2K onward you have at least 3 very nice wrapper ActiveX controls and classes at your disposal: the Internet Transfer Control, the XmlHttpRequest class, and the WinHttpRequest class).
No, in your case you will probably be stuck with replacing your "modules" (???) which probably means Forms (?) by a Form hosting a WebBrowser control.
However it will be clumsy to integrate what goes on in there with your other "modules." If that's needed you're going to probably need to spelunk the WebBrowser DOM to fish out data, inject data, etc.
Ideally you'd be moving to a Web Service model instead of a Web model. This opens a world of front end possibilities (Web, mobile, rich client) without the need for multiple back ends and is quite usable in VB6. Things have even gotten easier over time as SOAP is abandoned in favor of simpler, loosely-coupled RESTful Web Services.
What you have described is feasible to a degree, but when you start adding requirements like session cookie control it might get ugly. You may end up needing two logons in your program, one for the old/existing parts and another for the browser-based parts.
You might be better off just letting part go over to a browser and strip parts out of the old app and make people run both side by side.

.NET ASP webpage inheritance

I am new to .NET and ideally want to make several layers of abstraction for making a fairly complex website. Being the first layer handling login, authentication, etc, with another layer handling the built in apps (how they look, predefined functions, database connections), and the lower level will be specific app implementation details.
This favors uniformity as all apps will inherit from one place allowing for easier maintenance and rapid development of all the smaller apps once the overhead abstraction layers handle their responsibilities.
The only problem is I am not 100% sure where to start with .NET ASP webpage inheritance. I tried Google and searching but I may not be looking for the right thing. I am hoping with someone with experience on the matter may direct me towards resources to make this kind of webpage inheritance/abstraction easier!
I am using Visual Studio 2010.
Edit:
I also want to add the purpose to my question: Another individual is creating the base of the website which will handle authentication, portal, UI look, etc
I want to make an app base that uses their website framework and adds onto it standards that every app must meet, function library, any addition UI overrides not applicable from portal, etc.
From there a third layer that will directly inherit from the above app base framework (abstraction) and further specify based on the guide lines made.
I appreciate the feedback so far!
In ASP.NET you have 4 common ways to reuse code/abstractions to serve you application-wide
The first way is just using a base page, which will inherit the standard asp.net Page and share the common logic for all of your pages, as explained here
The second way is using a master page: a master page defines a common design (html / css - wise) for all the pages that use it throughout the application. It can also be accessed programmatically by pages that use it, and therefore share a common logic
The third way is using an http module: An http module is basically a class, which is responsible for handling an HTTP request before its handled by the expected pages code on the server, and it allows you to add any common logic you want your application to use (such as authentication / authorization handling, getting relevant user information from the DB, etc)
Global.asax: contains application/session wide event handlers, which allow you to handle those events in once place (everything from application starting to a user session ending)
Using modules and base page is the preferred way, if you want to build few applications, sharing common behaviour. A master page can be used as well, of course, if you want them to share the same design as well.
That's quite a broad question. Welcome to ASP.NET!
I would suggest researching these topics:
Web page inheritance -> Master Pages,
Skinning -> App_Themes,
separation of responsibilities -> MVP design
pattern for the Web Forms platform, or MVC if you have a choice.
Login, roles -> Membership

CassiniDev embedded in WinForm app?

I am trying to put together a winform app that also has a web interface that can interact with events generated from within the winform portion of the app. I am successfully running the cassinidev server from within the app and asp.net pages are being processed but I am still running into a few obstacles and I am not sure if they are even possible???
I am unable to use code behind pages. I have added the appropriate
attributes to the page directive but I still cannot access controls
from the aspx page.
I am unable to access classes from the web portion of the app. See
screenshot...
Maybe what I am trying to accomplish is not even possible but if anyone can help to point me in the right direction I would be most grateful!
I'm pretty sure you can't do that since the only thing you have available is the "website path" option.
You do however have the source and if you find some way of sharing data (maybe using the ApplicationPool) you could probably do that...but i'm guessing you'd still need to cast that data on startup to a static variable in your website.
Seems like too much work 2 me.
I'd suggest selfhosting WebApi as well and then just using that as the data layer of your website.
Both can be hosted in winforms and webapi CAN share static data directly from your code :)

ASP.NET Login Control - How Popular is It?

Sorry for the weird question.
I'm new to web development (spent the last few years in server side programming).
I'm suppose to write a small web site that will be accessible from the internet and suppose to have users management.
Currently I tend to use the ASP.NET login mechanism (using logic control, etc').
I have two simple questions:
1. Is it something "respected" ASP.NET web sites use?
2. Is it safe enough for the common web site?
Thanks a lot.
The built-in one is fine when you're just building the site and want a quick login page for now that works. It's perfectly safe - probably safer than anything you could build yourself, but I don't know of any "real world" sites that use it...
I have yet to build a single site where I have left it in-place, because there's always going to be a situation where you want to do something it doesn't cater for (for example: it uses a <table> which is a pain to style and frowned upon anyway).
Haven't seen it a lot on big pages, but it's just nice for a common web site. Nothing to worry about safety. But I always create my own login page/form anyway. If you have time, make your own, if you don't, just use the one.

Performing bulk processing in ASP.NET page

We need the ability to send out automatic emails when certain dates occur or when some business conditions are met. We are setting up this system to work with an existing ASP.NET website. I've had a chat with one of the other devs here and had a discussion of some of the issues.
Things to note:
All the information we need is already modelled in the ASP.NET website
There is some business-logic that is required for the email generation which is also in the website already
We decided that the ideal solution was to have a separate executable that is scheduled to run overnight and do the processing and emailing. This solution has 2 main problems:
If the website was updated (business logic or model) but the executable was accidentally missed then the executable could stop sending emails, or worse, be sending them based on outdated logic.
We are hoping to use something like this to use UserControls to template the emails, which I don't believe is possible outside of an ASP.NET website
The first problem could have been avoided with build and deployment scripts (which we're looking into at the moment anyway), but I don't think we can get around the second problem.
So the solution we decided on is to have an ASP.NET page that is called regularly by SSIS and to have that do a set amount of processing (say 30 seconds) and then return. I know an ASP.NET page is not the ideal place to be doing this kind of processing but this seems to best meet our requirements. We considered spawning a new thread (not from the worker pool) to do the processing but decided that if we did that we couldn't use the page returned to signify a success or failure. By processing within the page's life-cycle we can use the page content to give an indication of how the processing went.
So the question is:
Are there any technical problems we might have with this set-up?
Obviously if you have tried something like this any reports of success/failure will be appreciated. As will suggestions of alternative set-ups.
Cheers,
Don't use the asp.net thread to do this. If the site is generating some information that you need in order to create or trigger the email-send then have the site write some information to a file or database.
Create a Windows service or scheduled process that collects the information it needs from that file or db and run the email sending process on a completely seperate process/thread.
What you want to avoid is crashing your site or crashing your emailer due to limitations within the process handler. Based on your use of the word "bulk" in the question title, the two need to be independent of each other.
I think you should be fine. We use the similar approach in our company for several years and don’t get a lot of problems. Sometimes it takes over an hour to finish the process. Recently we moved the second thread (as you said) to a separate server.
Having the emailer and the website coupled together can work, but it isn't really a good design and will be more maintenance for you in the long run. You can get around the problems you state by doing a few things.
Move the common business logic to a web service or common library. Both your website and your executable/WCF service can consume it, and it centralizes the logic. If you're copying and pasting code, you know there's something wrong ;)
If you need a template mailer, it is possible to invoke ASP.Net classes to create pages for you dynamically (see the BuildManager class, and blog posts like this one. If the mailer doesn't rely on Page events (which it doesn't seem to), there shouldn't be any problem for your executable to load a Page class from your website assembly, build it dynamically, and fill in the content.
This obviously represents a significant amount of work, but would lead to a more scalable solution for you.
Sounds like you should be creating a worker thread to do that job.
Maybe you should look at something like https://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/
You can and should build your message body (templated message body) within domain logic (it means your asp.net application) when some business conditions are met and send it to external service which should only send your messages. All messages will have proper informations.
For "when certain dates occur" scenario you can use simple solution for background tasks (look at Craig answer) and do the same as above: parse template, build message and fast send to specified service.
Of course you should do this safe then app pool restarts does not breaks your tasks.

Resources