Setting a WEB project as a WSSF client

Topics: July and December Releases Forum
Mar 6, 2007 at 1:56 PM
I got some questions about how to set a host project (aka web projects) to act like a client (setting client project responsibility) so you may add service references and call other services from within that web project.
As you may already have noticed, when you open the responsibilities page on a web project, the only enabled check is the host project so you cannot set that project to act as a client.
That behavior is by design and that assume that the host project will actually act as a container for the service implementation and therefore it might not be the recommended place to add a client proxy to a remote service.
That scenario may be better suited for a service aggregation pattern that will likely be part of the upcoming version of WSSF (v3).
Now if you have a scenario where your client is a web project, then you may have different choices depending on how much time and effort you are willing to invest.

  1. Add a Winform client and generate the proxy and app.config files, and copy them to your client web project (update the web.config class and move the proxy class to the App_Code folder or better yet, to your business logic where you need to place the external we service call.
  2. Modify the WCF Guidance Package in order to allow setting client project responsibility on a web project.
  3. Investigate other scenarios with the Web Client Sofware Factory and how to call services from a web client.
Option #1 will be the easier and fastest since you don’t need to make any changes to the existing package. On the other hand, this will require manual updates that may be error prone and does not provide the benefits of the tooling automated guidance.
Now let’s say you are willing to update the package in order to do the manual steps described in option #1. If you want to experiment with this path, then perform the following steps:

  • Install the WCF Guidance Package source code and open the solution file
  • Go to the Recipes\WCF folder and open ConnectToWCFService.xml file.
  • Uncomment the following line inside the HostData section:
  <!--<CommandBar Menu="WCFWebProject"/>-->
This will allow the recipe to unfold on web projects.
  • Locate the “ClientProjectNamespace” argument and change the Expression attribute of the value provider as follow:
  Expression="$(ServiceReferenceName)"
This will avoid an exception thrown when you try getting the namespace property of a web project, so we’ll use the “ServiceReferenceName” argument value as the proxy namespace. If you don’t want to create the proxy class under a namespace or wish to use another value, just overwrite the expression attribute as “$(your value)” or an empty value as Expression=””.
  • Locate the “AddClientProxyAction” action and change the ItemName attribute as follow:
  ItemName="App_Code"
This will put the generated proxy inside the App_Code folder.
  • Save this file and Open the “ProjectResponsibilitiesPage.cs” file located under CustomPages folder.
  • Go to “OnLoad” override and comment the following line:
  //this.clientProjectCheckBox.Enabled = !(project.IsWebProject);
This will enable the Client project checkbox.
  • Save the file and Register the package right clicking over the WCF Guidance Package project and selecting “Register Guidance Package” option.
  • Finally, open your solution, enable the “Custom WCF Guidance Package” (modified source) and disable the “WCF Guidance Package” (original built-in package).

For those of you that asked for this scenario, let me know if you found this workaround acceptable and worked fine.

Thanks,
Charly