Create Custom SharePoint Web Service WSDL and Disco ASPX Files Automatically

I just completed a SharePoint developer tool called SPDev.exe. The initial purpose of this utility is to auto-generate the web service WSDL.aspx and Disco.aspx files needed for a custom SharePoint web service.

icon_shout Automatically generate your SharePoint disco.aspx and wsdl.aspx files in seconds!
icon_shout No need to manually copy or deploy your .asmx first!
icon_shout No manual editing!
icon_shout No Disco.exe needed!
icon_shout Automatically recycles the application pool (ensuring the newest assembly is loaded)!
icon_shout Automatically deploys the final SharePoint web service files (using the -deploy option)!
icon_shout No UI to enter data each time.  A command tool you can script for fast, consistent re-use!

After having to manually modify the disco.aspx and wsdl.aspx files by hand for the last three years, I finally found it tedious enough to create this utility.  There are other tools out there, but they require you to enter information into a Windows UI, they are not script-able, and still felt to tedious for me.  Call me lazy.  :)  Time is money.  This tool is a command line utility.  Simply execute the SPDev.exe command and your MyServiceDisco.aspx and MyServiceWsdl.aspx files are immediately ready for deployment.  SPDev also allows you to script the process.  Create a .cmd or .bat file and you’ll never have to enter any parameters again.  Another big benefit is you don’t need to use the Disco.exe utility since SPDev uses IIS and .NET instead which will always be on your development machine – since you are developing for SharePoint.  And, there are no temp files are generated (unless you want them generated).

Documentation for this utility is on my blog here: https://blog.crsw.com/spdev/

Advertisements

SharePoint RunWithElevatedPrivileges Example

The following example sends an email using elevated privileges.  This will elevate the privileges to execute using the service account.

The SPSecurity.RunWithElevatedPrivileges method taks a delegate method as its argument and executes that code with the service account.

SPSecurity.RunWithElevatedPrivileges( 
    delegate()
    {
        // Your code needing elevated permissions goes here.
    }
)

Example:

public void SendEmail(Email email) 
{ 
   SPSecurity.RunWithElevatedPrivileges(delegate() 
   { 
        SmtpClient mail = new SmtpClient();    MailMessage message = new MailMessage(); 
        message.From = new MailAddress(this.SenderAddress); 
        message.To.Add(email.To); 
        message.IsBodyHtml = email.IsHtml; 
                    
        if (!string.IsNullOrEmpty(email.Cc))            
            message.CC.Add(email.Cc); 
                    
        if (!string.IsNullOrEmpty(email.Bcc))            
            message.Bcc.Add(email.Bcc); 
                    
        if (!string.IsNullOrEmpty(this.ReplyToAddress))             
            message.ReplyTo = new MailAddress(this.ReplyToAddress); 
                    
        if (!string.IsNullOrEmpty(email.Subject))            
            message.Subject = email.Subject; 
                    
        if (!string.IsNullOrEmpty(email.Body))            
            message.Body = email.Body; 

        mail.Host = this.CentralAdminOutboundServerAddress; mail.Send(message); 
    });
}

Create a Live Meeting “Meet Now” link in your email signature

Wouldn’t you like to be able to hold an impromptu Live Meeting with your co-workers or clients by simply saying to them: “Click on my Meet Now link”.

Note: This posting discusses how to create a “Meet Now” link that you can place in your standard email signature. I also have a separate post “How to setup “Meet Now” for LiveMeeting 2007” that discusses how to configure your Meet Now options in LiveMeeting.

Here is an example of what this posting discusses; securely placing a permanent “Meet Now” link in your email signature.

Mark Wagner | Microsoft | Services | Senior Consultant II | LiveMeeting: Meet Now

Note: The Meet Now link above is a fake hyperlink since this is being posted on the Internet. :)

Why create a ‘Meet Now’ link in your email signature?
Having to schedule an impromptu Live Meeting and pass out the login code and/or custom link/URL, although it is pretty easy, it still takes longer than just telling your client/attendees to “Click on my Meet Now link.” Being able to use Live Meeting for an unplanned meeting is a great resource to have.  A Meet Now URL will always be the same since you can only have one Meet Now meeting at a time. Additionally, this URL can be posted on your internal My Site or placed in your email profile for easy access by your co-workers or clients.

Is it secure?
It sure is. The ‘Meet Now’ feature has existed in Live Meeting for quite some time now.  As long as you configure it as I have noted below, you have the necessary control measure to safely and securely share your Meet Now link.

Configuring Your Personal ‘Meet Now’ Signature Link:
The link in your email needs to be the Meeting Lobby URL. The URL can be found on your My Home page on the Live Meeting web site – after you have logged in.  It will look something like:

https://www###.livemeeting.com/cc/YOUR-COMPANY/meet/YOUR-LOGIN-NAME

Configuring Your Live Meeting Account:

  1. Login to the Live Meeting web site. I’m not sure what your URL is, but it will look something like this:
    https://www###.livemeeting.com/cc/YOUR-COMPANY
  2. Click on Meet Now Details link.
  3. Click on the Meet Now Options link.
  4. Enable the Meeting Lobby option. This will allow users to connect and wait in the lobby area. You will have to manually grant them access to your meeting when they arrive in the lobby. This prevents anyone from joining your meeting at anytime, such as the wrong clients. Although, I can say this has not been a problem for me.

Holding a ‘Meet Now’ Live Meeting:

Attendees: To hold a Live Meeting, have your meeting attendees simply click on the Meet Now link in any of your past emails, or as saved link somewhere. Once They will be waiting in the lobby until you join the Live Meeting and grant them access.

Presenters (You): As the presenter, you can join your Meet Now live meeting a few different ways.

  1. By logging into the Live Meeting web site using your Meet Now URL, which will look something like:
    https://www###.livemeeting.com/cc/microsoft/meetNow
  2. By logging into the Live Meeting web site using your standard Live Meeting login page, and then clicking the Meet Now link. This is effectively the same as option number 1.
  3. By configuring your Live Meeting rich client Meet Now button. I will need to dig into this a bit more because I had to manually build the URL to get this to work. But, it is handy to be able to just click on your Live Meeting rich client application and click the Meet Now button. It’s a little faster and direct.

Note: If there are attendees I want to be presenters, I always have them join just like any other attendee. Once they are in the meeting I promote them to a presenter. Keep in mind that once you do this they will be able to see your presenter password in the Meeting Details window, if they look for it.

SharePoint Module tag

Module:

– The Module tag is used to deploy files ‘logically’ to SharePoint when the given

feature is activated. This means they liv in the database, not physcally on disk

in the SharePoint 12 hive.

Module Attributes:

  • Path is relative to the current web site.

  • Url – is the relative url to the web site root (blank) or to the document library (i.e. "MyLibrary").

    • URL – This is the target location for your file. Effectively, this is the relative URL that points to the list that you want your files to be placed in. The relative url to the web site.

  • Path – this is the relative location between the feature and the physical file that you want to install. So if your file is in a sub-folder of the featue called "Images" then you would place "Images" as the Path. If your file is in the root feature folder (next to your feature.xml) then the "Path" would be an empty string ("").

  • RootWebOnly – this is a boolean value. If set to true, then this will only install when activated at the top-level site collection.

File Attributes:

  • Url is relative to the web site and contains the name of the file (i.e MyPage.aspx).

How to Create a Custom List with a Custom Content Type and Views

 

Steps to creating a new list with custom views and a custom content type:

Why use a custom content type?

  1. Create your site columns (fields) and content type, and deploy it to your development farm.
  2. Create a new generic Custom list on any site of your choosing.  Enable content type management on the list.
  3. Remove the default Item content type from the list.
  4. Add your new custom content type to the list, it should be the default.
  5. Customize your views as needed.
  6. Use the SharePoint Solution Generator to generate a List Definition for your new list.  The resulting generated Visual Studio project will contain a folder for the list that contains several form files (DispForm.aspx, EditForm.aspx, and NewForm.aspx) and an .aspx file for each view you created such as AllItems.aspx.  You will also have a schema.xml file which contains the content type definition, the views definition, and the fields section.  Leave the Fields and Views nodes/sections alone as they contain the definitions you defined.
  7. In the schema.xml file, in the ContentTypes node you will find a ContentType node defining your custom content type.  Comment (or delete) this entire node.  We will add this content type to the list via code instead of defining its association here declaratively.

The Major Task content type is commented out here because we are going to add
it programmatically via the ListInstances feature receiver.  This allows us to
properly promote all the fields in the content type to the list and enable
content type management on the list much more easily.

Logging to the SharePoint Log Files

Thanks to Brad Younge for sharing this a while back.  Below is an example on how to write to the SharePoint log files (located in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\LOGS folder).

catch(Exception e) 
{
   Microsoft.Office.Server.Diagnostics.PortalLog.LogString("Exception: {0} - {1}", e.Message, e.StackTrace);
}

You’ll likely want to prefix your log entries with a date and time stamp.

How To SysPrep Your Virtual PC/Virtual Server Images

This is something that anyone who uses Virtual Server or Virtual PC should know.

Overview

System administrators and software developers, especially those who are developing SharePoint solutions, often develop or test using virtual machines, either Virtual PC 2007 or Virtual Server 2005 R2.  Creating new virtual machines can be a time consuming effort; one we would all like to prevent from having to do every time we need a new virtual machine.  The great thing is that you can save all the time it takes to install Windows and the latest Windows Updates if you SysPrep a virtual machine.

What Is SysPrep?

SysPrep is a tool that allows you to prepare or “prep” a machine with the operating system along with any software you wish was pre-installed and pre-configured.  Once a machine is SysPrep’d, you have a new virtual machine that has the Windows operating system along with any additional software or features you want, such as IIS, pre-installed and pre-configured.  SysPrep allows you to create your perfect system configuration packaged so that you can have a new virtual machine up and running in just minutes.  And, it is available for both Windows Server 2003 and Windows XP.

Where Is SysPrep?

The SysPrep tool is located in a separate download from Microsoft called the System Preparation tool for Windows Server 2003 Service Pack 2 Deployment.

How To SysPrep

Building Your Virtual Machine Image

  1. Install your OS.  Windows Server 2003 R2 SP2 (or latest service pack), or Windows XP, or Vista.
    Note: I have not personally tried to SysPrep a Vista machine yet.
  2. Do NOT join the machine to a domain, at least not yet. (so you can leave the Admin password blank)
  3. Reset the Administrator password to blank.
  4. Get the latest Windows Updates.  Reboot and get latest again until there are no more required updates.
  5. Antivirus (Yes, your virtual machines should have antivirus software installed.)
  6. BGInfo (optional.  Just a tool I like to use that provides system information on the desktop background.)
  7. Daemon Tools CD Emulator.  (optional.  Just a tool I like to use to access ISO images.)
  8. Install the latest VM Additions.  (optional, but you will likely want to install this.  This comes with your Virtual PC and Virtual Server.)
  9. .NET Framework 3.5 SP1.  (optional.  This will include the latest .NET Framework for 1.1, 2.0, and 3.0.)
  10. Activate the Windows license (if you want to prevent having to re-activate Windows for each new virtual machine you create.)

Preparing to SysPrep: Creating a SysPrep.inf File

Before you can SysPrep you virtual machine, you need to create a SysPrep.inf configuration file.  This file contains the information about your machine.  It will also prevent you from having to enter you CD Key each time you create a new virtual machine from you SysPrep’d image.  Below is a sample of the SysPrep.inf file that you need to create.  This file configures the SysPrep process and automates boot up process.

  1. On your virtual machine, create a folder SysPrep at the root of your C: drive (C:\SysPrep).
  2. Copy the following text into a text file named SysPrep.inf.
  3. Enter the correct values for the following keys:
    1. TimeZone – the value of 10 is MST.  You may want to change this to your local time zone, but it is not required to do so.
    2. OEMDuplicatorsting – this should contain the name of the operating system you have installed on your virtual machine.
    3. FullName – your name, the name you would enter if you were installing Windows.
    4. OrgName – the name of your company, or blank.
    5. ProductKey – Your product key (CD key) license.

Sample SysPrep.inf file:

;SetupMgrTag 
[GuiUnattended]
    TimeZone=10
    OEMSkipRegional=1
    OemSkipWelcome=1
    EncryptedAdminPassword=NO
    OEMDuplicatorstring="Windows Server 2003 R2 Standard"
[Identification] 
    JoinWorkgroup=WORKGROUP
[Networking] 
    InstallDefaultComponents=Yes
[LicenseFilePrintData] 
    AutoMode=PerServer
    AutoUsers=50
[Unattended] 
    OemSkipEula=Yes
    InstallFilesPath=C:\sysprep\i386
[UserData] 
    FullName="YOUR NAME HERE like Mark Wagner"
    OrgName="YOUR COMPANY NAME HERE like Contoso"
    ProductKey=YOUR-PRODUCT-KEY-HERE
[SetupMgr] 
    DistFolder=C:\sysprep\i386
    DistShare=windist

Your SysPrep.inf configuration file is now ready to be used.

 

SysPrep-ing your Virtual Machine

SysPrep-ing your virtual machine takes just a minute or two.  Most of the time is simply shutting down your virtual machine.  Important: do not start this virtual machine back up or it will un-SysPrep your machine.  If this does happen, you can simply go through these steps below to SysPrep you virtual machine again.

  1. On your virtual machine, in the C:\SysPrep folder, run SysPrep.exe.
  2. Check the “Don’t reset grace period for activation” option.
  3. Make sure Shutdown mode is Shut down.
  4. Click the Reseal button to shutdown and package.
  5. Click OK to generate new SID’s.
  6. Your virtual machine will now shut down and be SysPrep’d.
  7. You now have a virtual image that is SysPrep’d, but not ready to be used.
  8. Before you use this image, you will need to make a backup copy of your virtual machine image files.  This will allow you to always have a SysPrep’d virtual machine ready and waiting.
  9. Backup your SysPrep’d virtual machine image files (.vhd, .vmc), and rename them to something you can easily understand and that describes what your image contains.  For example:
    1. Windows Server 2003 R2 SP2 SysPrep.vmc
    2. Windows Server 2003 R2 SP2 SysPrep.vhd
  10. You now have Your virtual machine SysPrep’d.  You can now use this image to quickly create a new virtual machine in minutes, with a new machine name and new unique System ID (SID) each time you use it.

Using Your SysPrep’d Image to Create a New Virtual Machine

Now, creating a new virtual machine will only take just a couple minutes.

  1. First, you need to copy your SysPrep’d image to a new name and to a new location where you will use this new virtual machine.  Copy your SysPrep’d image files (.vmc & .vhd) to a new location where you want your new virtual machine file to reside.
  2. Rename them to a new, appropriate name.  For example, if you are going to create a SharePoint server you might name them something like:
    1. MySharePoint2007.vmc
    2. MySharePoint2007.vhd
  3. Add this new virtual machine to you Virtual PC or Virtual Server; which ever you are using;
  4. Edit the configuration and make sure the virtual hard drive (VHD) is pointing to your new .vhd file.  In this example, the MySharePoint2007.vhd file.
  5. Configure any other items such as memory allocation and network cards as necessary.
  6. Start the virtual machine.
  7. You will receive a few prompts such as the name for you new machine.
  8. If you wish, you can now join you virtual machine to a domain.

SysPrep is a must have time-saving tool for anyone who uses Virtual PC and/or Virtual Server.

DisableLoopbackCheck – Unauthorized (401.1) Exception calling Web Services in SharePoint

Published on 10/14/2008

After upgrading to .NET Framework 3.5 Service Pack 1 on my SharePoint web servers I began to get the following Unauthorized exception.

Type: WebException, Exception Message: The request failed with HTTP status 401: Unauthorized.

This error really has nothing to do with SharePoint, and is really just an IIS web services related item.  This problem is due to an added bit of security included in the .NET Framework 3.5 Service Pack 1.  Here is the Microsoft KB article explaining the issue and how to work around the problem.  This Microsoft article refers to the problem coming after applying other service packs for Windows XP and Server 2003, but .NET Framework 3.5 Service Pack 1 is also now using this same bit of added security – the loopback check.

You will likely not encounter this problem on a single web server configuration and if you are using the server name to access the web site.

However, most enterprise SharePoint farms consist of at least two web servers that are load balanced.  This is where the problem exists.

Likely Cause:

  • You are calling your web services from your web servers using the load-balanced URL, not the server name.

This isn’t a bug.  There was a security fix built into the Windows networking stack that prevents a machine name that resolves to the loopback address from accepting a connection unless that machine name matches the NETBIOS name.

One option is to use the server name instead of the load balanced IP.  This should remedy the problem.  However, the standard method to apply configuration changes across a SharePoint farm is via SharePoint solution files.  This usually requires the configuration entries to be the same across all the web servers in the SharePoint farm, and using the load balanced URL is likely the most appropriate.

Suggested configuration changes to resolve this:

  • Add the DisableLoopbackCheck registry entry discussed in this Microsoft KB article.  Note: you will need to reboot your server before the DisableLoopbackCheck takes effect.
  • Be sure to add your load balanced host name for your web farm to the Hosts file on each front end web server.  Use the loop-back IP address (127.0.0.1).  This will ensure that each web server looks at itself to access the web services preventing any trips back out to the load-balancer – and possibly calling the web service another web server in the farm.  This will be much less efficient.
    • If this problem appeared to be inconsistent (sometimes erroring, sometime successful), this is most likely due having multiple web servers.  The call to the web service will be successful if by chance the load balance redirected the call to the same (self) web server to access the web service.  It will fail when trying to call across to a different web server.

References:

I’m mentioned (twice) in an MSDN Magazine article – SWEET!

It is an exciting moment to have two articles on my blog discussed and referenced in the May 2008 edition of MSDN Magazine.  Thanks to Ethan Wilansky for a great article in MSDN Magazine, and for making this happen!

MSDN-Mag-May2008CoverHere is the link to the MSDN Magazine article:
MOSS 2007: Automate Web App Deployment with the SharePoint API

Here are the links to two of my blog articles that are referenced in this MSDN Magazine article:
How To: Create a SharePoint Solution for an InfoPath Form 
How To: Modify the web.config file in SharePoint using SPWebConfigModification

Also, Shawn Feldman, a coworker, was mentioned for his terrific work in deploying SQL Reports.

Apply a Theme to all sub sites in SharePoint 2007

Apply a Theme to all sub sites:
(works for MOSS 2007 only, not WSS 3.0)
  1. Change the top site to the theme of your choice using the normal method in Site Actions > Site Settings > Site Theme.
  2. Navigate to the top site to see the newly applied theme.
  3. View the HTML source of the SharePoint page using the theme you want.
  4. Look for a link tag containing the .css file for the applied theme.  It will look something like this:
    <link rel="stylesheet" type="text/css" id="onetidThemeCSS" href="/apps/afe/_themes/Belltown/Bell1011-65001.css?rev=12%2E0%2E0%2E4518"/>
  5. Copy the href value to your clipboard or to a text file if you like.  It should look something like:
    /apps/afe/_themes/Belltown/Bell1011-65001.css
  6. On your top level site, go to the Site Actions > Site Settings > Master Page screen.
  7. Scroll to the bottom where the Alternate CSS URL section is.  Select the "Specify a CSS file…" option.
  8. Paste the path copied from the href above into the text box.
  9. Check the Reset all sub-sites to inherit this alternate CSS URL option.
  10. Click OK.
  11. Navigate to your sub-sites and verify the theme has been applied.