Registering a WSS 3.0 Hosted Web Service As Part of the Build Process 

Tags:

The problem: You are developing a web service you want Windows SharePoint Services 3.0 to host, but you have not completely finished the design of the web service.

 

Recently, I needed to create a web service hosted by WSS 3.0. The manual steps required to register the web service in the WSS 3.0 root folders ISAPI directory can be tedious and time consuming if your web service interface design is not complete when you begin coding (not to imply you should be coding without doing any design work!). I initially followed the steps described in the MSDN Walkthrough: Creating a Custom Web Service article (you should do this too if you want to follow along in code!). Once I had created the web service, I quickly realized that, since my web service definition was subject to change, copying files to the layouts folder, running disco.exe, manually editing the resulting files and then copying the edited files to the ISAPI directory was not going to increase my happiness!

 

The solution: Use the Visual Studio project formats, MSBuild and some custom MSBuild tasks to make your life easier.

 

After recently finding and thoroughly enjoying the value add of the STSDEV Tools (thank you Ted Pattison!), I decided to leverage the pattern of modifying the build process. I dove into how the STSDEV Tools work and patterned a possible solution to my problem of registering WSS web services during my development builds. The solution described here takes advantage of this pattern and lets Ctrl+Shift+B build and register the web service for you during development.

Let's walk through the basic steps of the solution (for you impatient types, the complete file can be found here).

 

1. Create a new webservice.targets file. First, you need a targets file that can do all of this work for you. Initially, I started with a Project file and set up some properties I knew I would need.
<?xml version="1.0" encoding="utf-8"?>

<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<
PropertyGroup>

<MAKECAB>"C:\Windows\System32\makecab.exe"</MAKECAB>

<DISCO>"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\disco.exe"</DISCO>

<STSADM>"$(ProgramFiles)\Common Files\Microsoft Shared\web server extensions\12\bin\stsadm.exe"</STSADM>

<MAKECAB>"C:\Windows\System32\makecab.exe"</MAKECAB>

<GACUTIL>$(ProgramFiles)\Microsoft SDKs\Windows\v6.0A\Bin\gacutil.exe</GACUTIL>


<
WSFileNameRoot>REPLACE_WITH_YOUR_SERVICE_NAME</WSFileNameRoot>

</PropertyGroup>

Remember to replace the WSFileNameRoot property with the value for your service if you try this solution out.

 

2. Next, we need to import a task that will help us do some text manipulation once we have created the disco and wsdl files. See the Note below for how to obtain this task.
<UsingTask AssemblyFile="$(SdcTasksPath)Microsoft.Sdc.Tasks.dll" TaskName="Microsoft.Sdc.Tasks.File.Replace"/>

 

3. Now we need a Target that will enable us to register the web service by deploying the assembly to the GAC.
<Target Name="Register" DependsOnTargets="Unregister">

<!-- Register in the GAC, copy to layouts and run DISCO.exe to get the WSDL and DISCO files-->

<Exec Command="&quot;$(GACUTIL)&quot; -iF &quot;$(TargetPath)&quot;"/>

 

4. Now, we need to copy the asmx file to a location that is http accessible, and call disco.exe to create DISCO and WSDL files, and change the file extensions.

<
Copy SourceFiles="$(ProjectDir)$(WSFileNameRoot).asmx" DestinationFolder="$(LAYOUTS)\$(ProjectName)"/>

<Exec Command="$(DISCO) $(LOCALHOST_LAYOUTS)$(ProjectName)/$(WSFileNameRoot).asmx" WorkingDirectory="$(ISAPI)/$(ProjectName)"/>
<!--
Rename the *.disco and *.wsdl files to match the service asmx file with *disco.aspx and *wsdl.asmx suffixes-->
<
Exec Command="ren &quot;$(ISAPI)\$(ProjectName)\$(WSFileNameRoot).wsdl&quot; &quot;$(WSFileNameRoot)wsdl.aspx&quot;"/>
<
Exec Command="ren &quot;$(ISAPI)\$(ProjectName)\$(WSFileNameRoot).disco&quot; &quot;$(WSFileNameRoot)disco.aspx&quot;"/>

 

5. Next, we use the custom Tasks from the SDC Tasks to replace the service binding locations in the disco and wsdl files to be SharePoint aware. For full details, get dirty and check out any of the services found in the ISAPI directory in the 12 Hive.
<!-- Use Sdc Tasks File.RegEx or File.Replace to udpdate the disco and wsdl files-->

<Microsoft.Sdc.Tasks.File.Replace Path="$(ISAPI)\$(ProjectName)\$(WSFileNameRoot)disco.aspx" …

 

6. To make sure the service changes are caught and can be updated by a "Reload" of any web service references, we call IISRESET to reset the service and ensure our changes are updated.

 

7. To make sure we are removing the old registered files before we start any of the registration we create an "Unregister" dependency target.

<Target Name="Unregister">

<!-- simple remove of the files that are copied to ISAPI direcotry and removal from GAC -->

<Exec Command="&quot;$(GACUTIL)&quot; -u &quot;$(ProjectName)&quot;"/>

<Delete Files="$(LAYOUTS)\$(ProjectName)\$(WSFileNameRoot).asmx"/>

</Target>

 

8. Now, to tie this into your Visual Studio project, simply right click your web service class library project in Solution Explorer, and select "Unload Project". Then right click the project again and select "Edit <your project name>" to open in an XML Editor.

 

9. Add an Imports statement to import our targets file into your project. You can add this line under the Imports statement for the CSharp.targets towards the bottom of the file.
<Import Project="webservices.targets" />

 

10. Add a call to your Register target by adding the following to the AfterBuild target of your project like so.
<Target Name="AfterBuild">

<CallTarget Targets="Register" />

</Target>

 

That's it! Now right click on your project in Solution explorer, select "Reload Project" and hit Ctrl+Shift+B to build. Check the 12 Hive's ISAPI directory for a subdirectory with the same name as your project and your as*x files should be in there. You can now create web references to this web service just like you would any other WSS 3.0 hosted web service.

 

Finally, there are two lessons learned in this whole process:
- always remember to unload and reload the project that contains the webservices.targets file since changes made to this file will not take effect until the project is reloaded in Visual Studio.
- to help in debugging, turn up build output verbosity by clicking Tools::Options::Projects and Solutions and increasing the "MSBuild project build output verbosity:" to "Diagnostic" to enable detailed information in the Output window

 

Hopefully this can help someone else save a little time when developing a WSS 3.0 hosted Web Service. Let me know if you have some suggestions or improvements, or even a better way altogether. I'd be interested in learning an alternative approach.

 

[NOTE: This solution assumes 1) that the development environment is a Windows Server 2003 instance with WSS 3.0 installed, and 2) uses the Sdc custom MSBuild tasks located at http://www.codeplex.com/sdctasks in order to manipulate file content. You will need to download and install these tasks in order to use this solution in your project.]

 
Posted by Pete Skelly on 2-Jul-08
3 Comments  |  Trackback Url  |  Link to this post | Bookmark this post with:        
 

Links to this post

Comments


Kirk Liemohn commented on Wednesday, 2-Jul-2008
Great blog, Pete! A note to others - thanks to Pete I used this on a recent project and my web services were not located in the GAC. Some day we may update this targets file to not require the GAC, but for now you simply have to make sure it is signed when you do this build and then you can remove the strong name (if you like) for your other builds once you are happy with the WSDL.


commented on Tuesday, 21-Oct-2008
Integrating Microsoft Windows SharePoint Services 3.0 Contacts with Outlook 2007 With Outlook 2007 and Windows SharePoint Services, you may now synchronize information in two directions for items in Contacts Lists. Follow these instructions to connect Outlook 2007 to your SharePoint Contacts: 1. On the Quick Launch menu, under the Lists section, click on your Contacts. 2. Click Actions, and then select Connect to Outlook. 3. An Internet Explorer Security warning dialog box might appear stating: A website wants to open web content using this program on your computer. If so, click Allow. 4. Outlook 2007 opens, and you might be asked to supply your user name and password. A Microsoft Office Outlook dialog box appears stating: You should only connect lists from sources you know and trust. Click on Yes. 5. Your SharePoint contacts will now appear in your Outlook 2007 and both will be fully synchronized. NOTE: You will need to have Outlook 2007 installed on your computer and make sure your SharePoint user has proper access permissions to the Contact List before proceeding.


情趣用品 commented on Tuesday, 18-Nov-2008
情趣用品,情趣用品,情趣用品,情趣用品,情趣,情趣,情趣,情趣,按摩棒,跳蛋,充氣娃娃,免費A片,AV女優,美女視訊,情色交友,免費AV,色情網站,辣妹視訊,美女交友,色情影片,成人影片,成人網站,A片,H漫,18成人,成人圖片,成人漫畫,情色網,日本A片,免費A片下載,性愛,A片,色情,成人,做愛,情色文學,A片下載,色情遊戲,色情影片,色情聊天室,情色電影,免費視訊,免費視訊聊天,免費視訊聊天室,一葉情貼圖片區,情色,情色視訊,免費成人影片,視訊交友,視訊聊天,視訊聊天室,言情小說,愛情小說,AIO,AV片,A漫,av dvd,聊天室,自拍,情色論壇,視訊美女,AV成人網,色情A片,情趣用品,A片,免費A片,AV女優,美女視訊,情色交友,色情網站,免費AV,辣妹視訊,美女交友,色情影片,成人網站,H漫,18成人,成人圖片,成人漫畫,成人影片,情色網,sex,情趣用品,A片,免費A片,日本A片,A片下載,線上A片,成人電影,嘟嘟成人網,成人,成人貼圖,成人交友,成人圖片,18成人,成人小說,成人圖片區,微風成人區,成人文章,成人影城,情色,情色貼圖,色情聊天室,情色視訊,情色文學,色情小說,情色小說,臺灣情色網,色情,情色電影,色情遊戲,嘟嘟情人色網,麗的色遊戲,情色論壇,色情網站,一葉情貼圖片區,做愛,性愛,美女視訊,辣妹視訊,視訊聊天室,視訊交友網,免費視訊聊天,美女交友,做愛影片,情境坊歡愉用品,情趣用品,情人節禮物,情惑用品性易購,av,情趣用品,a片,成人電影,微風成人,嘟嘟成人網,成人,成人貼圖,成人交友,成人圖片,18成人,成人小說,成人圖片區,成人文章,成人影城,愛情公寓,情色,情色貼圖,色情聊天室,情色視訊,情色文學,色情小說,情色小說,色情,寄情築園小遊戲,情色電影,aio,av女優,AV,免費A片,日本a片,美女視訊,辣妹視訊,聊天室,美女交友,成人光碟

Name:
URL:
Email:
Comments:

CAPTCHA Image Validation