How to start

Topics: Developer Forum
Aug 16, 2007 at 2:12 PM
Edited Aug 16, 2007 at 2:13 PM

Newbie need some help. I've already studied the forum, the documentation, but still I have no general vision how to use the framework.

What I need is to add some validation features to existing WebService due a lack of this functionality in .Net WS support.
The most important things are I need validation based on XML configuration files with rule sets. The problem is that class almost identical to examples aren't validated against XML configuration.
I've already added App_GlobalResources dir, valtest.validation.xml file is already there, but no rules applied to it. Validation works only with "[ ]" directives in the code - I want to avoid.
Any help will be very appreciated. I'll try to write some basic tutorial if I manage framework utilization - for the other newbies.

Here are some of my code: XML config doesn't work.
Aug 17, 2007 at 7:24 AM

The ConfigurationService.AddAssembly method only works for xml files that are embedded in the assembly you pass in. To embed a file as a resource view the properties of the validation.xml file in Visual studio and set the build action to “Embedded Resource”.

Also note that ConfigurationService.AddAssembly should only be called once per appdomain. So you should be calling it in the Application_Start of your Global.asax.cs.

If you do not want to embed the files as resources you can add the validation configurations by directly adding the files. You do this by calling the ConfigurationService.AddXmlFile method and pass in the path to the xml file. Note that in this case xml file does not need to have the suffix validation.xml. Again you should do this once per appdomain.

If you still have any issues contact me through my profile page and I will give you a hand with the code.

And I would appreciate a tutorial on using xml configuration if you get around to writing it.

Aug 17, 2007 at 7:34 AM
Also have you had a look at the quickstarts?
There is a sample on how do a website.
This would be a good starting point for you.
Aug 20, 2007 at 11:16 AM

First of all thanks for your support. I really appreciate it.

I can't find "Embedded Resource" build action in WebSite project in VS (2005 Pro). I’m not an expert in VS, but it looks that WebSite project does have another set of options. So manual adding on XML is the only option I know.

Can you clear a little second paragraph. In the WebSite VS project generally I don't have Global.asx.cs. Additionally I do not have any, let say, application constructor (equivalent of Main() ) to call only once.
As far as I know the default Service method is called every time request comes (in WebService type of WebSite project) and there I can store something in HttpApplicationState. I don't know if I have to call ConfigurationService.AddAssembly in this Service method or I should call it only once per Application instance.
To be more clear of this, Application instance is server wide state of WebSite application. Every time new version of applications is delivered Application State is created as new. At first request (to this instance) I can store some mark that .AddAssembly was already called here and do not call it again in every next request. Is it the right approach?

Aug 20, 2007 at 2:35 PM
Edited Aug 21, 2007 at 1:15 PM

For starters ensure you are using "Web Application Projects" not "Web Site Projects".

A bit of history... "Web Site Projects" were a new "feature" of VS2005 for developing websites. There are many flaws with "Web Site Projects", some of which you have highlighted, but the main one being its inability to work with source control. MS faced so much criticism for "Web Site Projects" that they reintroduced the VS2003 approach and called it "Web Application Projects". "Web Application Projects" are available in service pack 1 for VS2005.

Once you have installed SP1 you can do the following
  • create a new "Asp.Net Web Service Application".
  • Then using the "Add new item" dialog add a new "Global Application Class"
  • That will give you a "Global.asax.cs" file with ApplicationStart and ApplicationEnd methods.
  • Inside the Application_Start you can call ConfigurationService.AddAssembly.
  • Also note that since you are using a "Asp.Net Web Service Application" you can view the properties of an xml config file and set the "Build Action" to "Embedded Resource"

As for loading validation once in your “Application” instance.... It is not really right or wrong. You should use whatever suits your needs and you are comfortable with. I have found the ApplicationStart method to work so I stick to that. If you choose not to use ApplicationStart i would recommend doing it in a static constructor of Application rather than storing a flag and checking on every instantiation.

There is one other pointer. You should consider placing your business and validation logic in a standalone assembly (Class Library). Your xml validation files would then be embedded in that assembly. This would give you the ability to do unit testing and, optionally, writing a different front end. This is what I have done with the Quickstarts. If you downloaded the source you can see that there is a website and a windows application using the same business assembly.

Hope this has helped.

Aug 27, 2007 at 5:50 PM

It helps a lot! Now everything looks clear. Although I didn't find SP1 for VS2005, I found separate fix with required update.Today I found some time to test it and it works pretty well with couple of ways of adding validation rules - standalone in code, with Embedded Resources and with outer xml files. Additionally in both projects templates "Web Site Application" and "Web Service Application" the option "Embedded resource" for xml files is available. You mention it but my target is rather to left the validation rules flexible, at least for now.

Thanks once again for help.

Finally I found a SP1 for VS2005, but it is called "Microsoft® Visual Studio® 2005 Team Suite Service Pack 1" what is a little bit confusing. After installing the fix I realize that to install SP1 I should uninstall this fix. :) No comment...
Aug 27, 2007 at 11:08 PM
Have a read of this

To Quote

“Support for Web Application Projects is now a feature of Visual Studio 2005 Service Pack 1. A separate add-on and update to Visual Studio is no longer needed. If you did install the Web Application Projects Add-on you must first uninstall it before installing Visual Studio Service Pack 1.

Steps for installing support for Web Application Projects:
If you have the “Microsoft Visual Studio Web Application Projects” add-on installed, uninstall it.
Install Microsoft® Visual Studio® 2005 Team Suite Service Pack 1”

Does that make sense?

As for the installing “Microsoft® Visual Studio® 2005 Team Suite Service Pack 1" according to this
that “includes SP1 updates for Standard, Professional, and Team Editions of Visual Studio 2005”. So yes that is the correct one to install.

And yes the whole situation is confusing.

Sorry but i cannot answer these questions :)

Aug 28, 2007 at 10:46 AM
What can I add from my experience: I tried to install VS80sp1-KB926601-X86-ENU. I hadn't know it is really Visual Studio® 2005 Team Suite Service Pack 1 - I had only this file in our VS install repository and assume it is SP1 from its name. After installation there was no Web Application project template available :(. I thought I miss something and dug a little, and I found mentioned fix. I tried to install it and then new project template become available.
The reason probably was caused by another developer fixes like WSE and SQL Server Express tools.

Finally, I have what I need but in a really strange way. I'll try to do this "by Microsoft" way on clean installation in near future...
Aug 28, 2007 at 11:00 AM
Sorry for a little OT but on mentioned webpage you can find unconsisted information. In couple lines below your cite there is a state:

To fully enable Web Application Projects in Visual Studio 2005, you will need to first install Microsoft Visual Studio 2005 – Update to Support Web Application Projects, then this add-in. Visual Studio 2005 Web Application Projects are not supported in Visual Web Developer Express Edition.

Does it mean that the proper way is:
  • Install VS2005
  • Install fix with Web Application project support
  • Install SP1 which is:
    • Uninstall above fix
    • Install SP1

As I mention before, I did this in a different way and now it works. First VS 2005, then SP1 and at the end the fix. :) Confusing, but works.

Aug 28, 2007 at 1:37 PM
The way I understand it (and have done this several times) is as follows

  • if you are building a clean machine you should
  1. install VS2005
  2. install SP1
  3. do not install the web application plugin

  • if you already have the web application plugin installed
  1. uninstall web application plugin
  2. install SP1
  3. do not install the web application plugin

Basically the web application plugin is made redundant with SP1

Although for more detail information you should probably post on some vs,net newsgroups.
Aug 28, 2007 at 1:39 PM
I have just re-read your post and noted the "fix" you mentioned to make web application project visible with SP1.
As i have never had a problem with them not showing up i cant comment on that one
sorry. :(