Eric's Blog

Day to day experience in .NET
Welcome to Blogs @ IRM Sign in | Join | Help
 Search

Disclaimer

The content of this site is my own personal opinion and does not in any way represent my employer, it's subsideries or affiliates. These postings are provided "AS IS" with no warranties, and confer no rights.

This Blog

Customizing WSSF 101

There are three levels of modifications that can be done of the Web Service Software Factory (WSSF), or any software factory that pattern & practices deliver:
  • A simple change is to restruct the projects and their responsibilities in the solution.
  • A moderate change is to change or add code to templates.
  • A hard change is to change or add recipes which requires understanding of GAX and GAT.
 
Simple changes can easily be done after running the initial recipe. Right-click on the solution and choose "Unlock Solution" from the Web Service Software Factory menu. When this is done it is possible to remove projects and assign the removed projects responsibilities to other projects. For example removing the FaultContracts project and then assign that responsibility to the DataContracts project.
 
To make a moderate or hard change it is necessary to open the software factory solution and edit the files, recompile it and register it with Visual Studio. The source code is not automatically installed by the WSSF, but there are installers for the different packages in the "Microsoft Service Factory\Source Code" folder. The WCF Guidance Package solution has seven projects and 4 test projects, split in folders called Libraries, Package and Tests. WCF Guidance Package project is most likely where the files that are interesting for modification belongs, but before digging in the details, it would be good to look at the structure of guidance packages.
 
Guidance packages contains VS Templates and Recipes. The VS Templates is the solution with the project structure and recipes are the support that the guidance package expose to the user. A recipe executes one or more Actions. The actions can have in and out parameters that can be set either through Wizards that collects values from the user or by Value Providers. A value provider can for example set a parameter to the current selected project or file. It's quit common for the last action to be an action that runs a T4 Template. A T4 template is like ASP files with <% %> tags with code that inserts dynamic values.
 
Back to the WCF Guidance Package project. It contains folders that is called Templates, Actions, ValueProviders, Editors and CustomPages (that are part of Wizards). There are also a WCF Guidance Package.xml file that defines the guidance package itself and which recipes it contains. The first thing to do when modifying the package is to open the file and set the Name, Caption, Description and Guid attributes of the GuidancePackage root element.
A moderate change could be to add inheritance to a base class for one of the classes that is created by WSSF through a T4 template. The template class for the service implementation (Templates/T4/ServiceImplementation.t4) looks like this out of the box:
 
[ServiceBehavior(Name = "<#= ServiceBehaviorName #>", Namespace = "<#= ServiceBehaviorNamespace #>")]
public class <#= ServiceImplementation #> : <#= ServiceContractInterface #>
{
}
 
After adding a base class inheritance the class would look like this (the change highlighted in yellow):
 
[ServiceBehavior(Name = "<#= ServiceBehaviorName #>", Namespace = "<#= ServiceBehaviorNamespace #>")]
public class <#= ServiceImplementation #> : IRM.ServiceModel.ServiceImplementation, <#= ServiceContractInterface #>
{
}
 
When adding inheritance it would also be good if the project had a reference to the assembly when the solution is created so that the user wouldn't have to add that afterwards when getting a compile error. Even though it is possible to export a modified solution and use it as the VS Template in the guidance package, I have found it just as easy to edit the project files myself, especially since we have refined the package through out the project time when we discover possible improvements. The project file for service implementation can be found in Templates/Solutions/Projects/WCFServiceImplementation/ServiceImplementation.csproj. The project files are simple msbuild xml files and the reference is to be added in the itemgroup where there already are <Reference> tags. The easiest way to do it is to open a project-file that has the correct references set in notepad and then just copy them over.
 
To test the modified version of the guidance package, right-click on the project and select "Register Guidance Package" (next time choose "Quick Register" if no major modifications have been done) and start a new instance of Visual Studio and the new Guidance Package should be available in the "Guidance Packages" folder of the "New Project" dialog. If "Register Guidance Package" is not available in on the popup menu, just make sure that the "Guidance Package Development" package is enabled for the solution by opening Guidance Package Manger from the Tools menu. If it's not click on "Enable / Disable Packages…" and check "Guidance Package Development".
Published den 18 maj 2007 11:01 by ericqu
Filed under: , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
(optional)
(required) 
Submit
Powered by Community Server, by Telligent Systems