Tuesday, April 24, 2007
As soon as you start to do anything non-trivial using JavaScript (like calling web services for example) you'll realise that SharePoint is up to its old tricks and hiding error messages from you again. (While this "error handling" fad might be all the rage in production environments, it's not welcome on my development machine, thank you very much.)
Point your favorite text editor at 'C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033\INIT.JS' and Ctrl-g to line 574 where an event handler is registered for the window's onerror event; comment it out to resume normal service.
Friday, April 20, 2007
I've been doing some work recently with custom SharePoint web services, which is working out very nicely for the most part. However, because SharePoint virtualizes its URLs you cannot have ASP.NET auto-generate the disco and wsdl files, and the steps to manually create them are tedious at best. I had a quick look around to see if there were any tools to automate this and found the WSS Web Service DISCO and WSDL Generator Helper on Code Project.
Since it originally targeted .NET 1.1 and SharePoint 2003, I've update it to .NET 2.0 and added a little more error checking for good measure. Internally, disco.exe is used to generate the disco and wsdl files, so the .NET 2.0 version will need to be in the same directory as the executable. You'll find a copy in 'C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin' or somewhere similar on your development machine.
This is a quick fix to my immediate problem, longer term I may (or may not) create a version to use in Visual Studio builds. I'm not sure what the rules are around the stuff on Code Project, but for now you can download my updates from the links at the bottom of this post. I'll drop the original poster a message and merge my changes if necessary.
WebServicePackager.zip
WebServicePackagerSource.zip
Tuesday, April 10, 2007
Update: This post describes the use of Sysprep with SharePoint in Standalone mode. I've since posted a follow-up that updates this to work with a Complete install and SQL Server.
If you're doing SharePoint development you're probably doing it on a virtual machine, and if you're not you probably should be. Often it's useful to have more than one machine available whether that's for multiple clients, projects or developers. If you're working in a standalone or workgroup environment you can probably get away with creating one virtual machine and copying it as many times as you need additional machines. In a domain environment however, this isn't really going to work for you. You need to change the SID of the machine, give it unique name on the network, join the domain and ensure that SharePoint is configured ready for you to start developing on. One way to tackle this would be to use NewSID, rename, join the domain manually and then fix SharePoint. A better solution would be to use Sysprep and automate the whole process.
First, create a new virtual machine, install Windows Server 2003 and run Windows Update making sure you install the .NET Framework 2.0 and 3.0. Once those are installed add the Application Server Role from the Manage Your Server utility. Next, install WSS or MOSS, selecting Typical from the install options to perform a standalone installation. Once this has finished the SharePoint Products and Technologies Configuration Wizard will run. It's important that you don't run the wizard at this time, you'll see why later on. Finally, finish off the installs with Visual Studio 2005 and any of your other favorite tools. Others have written about how to install a standalone SharePoint environment in more detail and there are also instructions available on TechNet for both WSS and MOSS.
Next, you need to grab the correct version of Sysprep, there's one for each Windows Server 2003 Service Pack. I originally put this together using Sysprep for SP1, before Windows Server 2003 Service Pack 2 was released, but I don't know of any reason why you shouldn't use Sysprep for SP2. While you're at it, download WssSysprep.zip which contains the scripts and settings we'll use with Sysprep.
If you're using SP1, Sysprep is distributed as a CAB file which you should extract to c:\Sysprep. The SP2 version looks like it's distributed as a hotfix so this will need installing, but the net result should be the same. Once you've done that, extract the contents of WssSysprep.zip (which you've already downloaded if you're paying attention) to c:\ which will add a couple of files to c:\Sysprep and create c:\Scripts.
Sysprep is configured using sysprep.inf which you need to create in c:\Sysprep with settings specific to your environment. You can either create this file by hand using ref.chm as a guide, or if you prefer you can use Setup Manager (setupmgr.exe) to help you. To ensure that this is a completely automated process, you need to include enough information in the configuration file to prevent you from being prompted for more during setup. I have included my sysprep.inf file renamed as sample.inf as a reference. In addition to your own preferences, you need to include the [GuiRunOnce] section from sample.inf. Any commands entered here are executed after the first user logon following setup. In this case, we call wssconfig.bat which will provision a SharePoint site and configure it ready for use.
Since it's where most of the magic happens, let's take a look at the important bits of c:\Scripts\wssconfig.bat.
1: "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\PSCONFIG.EXE" -cmd configdb create
2: "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\PSCONFIG.EXE" -cmd setup
3: "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\STSADM.EXE" -o siteowner -url http://localhost -ownerlogin %userdomain%\%username%
4: "C:\Scripts\wssdebug.exe" http://localhost /enable
Earlier, when you installed SharePoint you didn't run the Configuration Wizard. If you had, a site would have been provisioned but it wouldn't have survived the Sysprep process. Instead, we have Sysprep call this batch file which uses psconfig.exe to provision a site for us after setup has run. (The use of psconfig.exe in this way came from this post.) Sysprep calls this file with the "/sysprep" switch to indicate that there are no existing sites to be removed. Once psconfig.exe has created the site collection we use stsadm.exe to set the current user as the site collection owner. This will require administrative privileges to run, so in an environment where you're potentially distributing this to several developers I would add the built-in NT AUTHORITY\INTERACTIVE group to the local Administrators group. I'm happy to do this in a development environment but you may prefer to add specific domain accounts which will also be fine. Last of all, we run wssdebug.exe to make a few tweaks to make SharePoint a little more developer friendly.
That's pretty much all we need to make this work. However, I would recommend you make a couple of other changes now to save you making them each time you create a new machine. I like to have the SharePoint "bin" directory included in my path to make it easier to run stsadm.exe, and a shortcut to the 12 hive on the Desktop is always useful. Andrew Connell has a number of other good suggestions. I'd also set the IE and Firefox home pages to localhost now as well. Bear in mind that you're likely to want these tweaks available to all users of the machine so create desktop shortcuts in the All Users profile and consider updating the Default Profile with user specific settings. The Sysprep documentation suggests that any settings made to the Administrator profile will be copied to the Default Profile when Sysprep runs. This never seems to work for me (maybe it's an XP only thing?) so instead I follow this Knowledge Base article. Finally, you might want to compact your virtual hard disk since it may have become fairly sizeable by now.
At this point I'd take a copy of the virtual hard disk to make it easy to come back and make changes in the future. Once that's done you can go ahead and run Sysprep to reseal the machine. (You can use the included sysprep.bat which simply calls Sysprep.exe with the /reseal, /mini and /shutdown switches.) Once the machine has shutdown I like to mark the virtual hard disk file as read-only and remove the associated virtual machine to prevent me starting it up accidentally.
You now have a virtual hard disk which you can copy as many times as you like, for as many developers as you need. (And if you zip it up it should hopefully still fit on a single DVD.) The first time it starts up it will give itself a unique name and join your domain. When the first user logs on a new site will be provisioned, the user will be made site collection owner and SharePoint will be configure for debugging.
Monday, April 02, 2007
Back in November 2005 each attendee of Microsoft's Ready to Launch events came away with (amongst other things) a voucher entitling them to take one of six .NET 2.0, SQL 2005 or BizTalk 2006 exams. Fast forward some 17 months and despite the voucher having long since expired, I finally got around to taking and passing 70-536.
Everyone's got their own opinion of certification, and I would certainly agree that exams like this are far from perfect. It seems to me that one of the biggest problems (along with brain dumps) is that of interpretation. What does it mean to have passed this exam? In this case for example, it's important to remember that you're learning virtually nothing about a candidates ability to write elegant, maintainable code, and even less about their broader skills as a developer. And it's this that frustrates people so much when that person who's been fast tracked through an entire certification program by their employer starts showing off their newly be-logoed business card and lapel pin. But I digress...
I found this exam useful. I come away with a broader awareness of the framework having spent time looking in areas I wouldn't have done otherwise. (I also have an additional 76 folders in "D:\Documents\Visual Studio 2005\Projects" to show for it.) I think it can be tempting to jump straight into developing for your target platform, whether that's Windows Forms, ASP.NET or SharePoint even, without taking the time to look at the goodness available to you in the framework. This isn't VBScript, there are thousands of types at your disposal and although you're likely to use Google before rolling your own MD5 implementation, there are more subtle features that must regularly be rewritten (probably less well) when they needn't be. And who's looked at say Code Access Security? I'm sure you have, but for every one of you who has I'll bet I can find two of them that haven't. Having said that, the one criticism you might make is that some of the content of the exam (e.g. GDI+) doesn't really sit that well with the Application Development Foundation title, and could make way for some more content around say generics and their use beyond generic collections.
Until last week it was 1998 when I last took an MCP exam. I'm not sure it will be as long until I take another.