Patch for AddAsyncWebServiceProxyAction

Topics: CAB & Smart Client Software Factory
Jan 13, 2007 at 10:58 PM
I use Subversion as my source code control solution and one of the things that it does is adds a _svn directory to all controlled directories. The problem is that if I want to refresh a "Smart Web Reference" I need to delete the entire directory and regenerate it. This meant that the _svn directory was also deleted. This became frustrating and I have just managed to code a solution to it.

The following code is a patch to AddAsyncWebServiceProxyAction. I have left enough of the original code top and bottom to enable you to place the patch in your code.

What the code does is it first detects if the Folders to be added already exist. This was the first point of failure and the cause of the error message. Next it clears out the Commands directory in case your refresh actual removes a command. Next it Deletes the "simpleClassName".cs file from the project. The presence of this file causes GetServiceMethods to return zero methods and therefore not refresh anything.

Anyway, I hope the code is useful to someone. BTW, it applies to the June 2006 CTP release.

Cheers, Greg.

string rootNamespace = GetGlobalValue("RootNamespace");
string projectNamespace = project.Properties.Item("DefaultNamespace").Value.ToString();
string nameSpace = String.Format("{0}.{1}", projectNamespace, _serviceName);

//ProjectItem mainFolder = project.ProjectItems.AddFolder(_serviceName, EnvDTE.Constants.vsProjectItemKindPhysicalFolder);
ProjectItem mainFolder = null;
foreach (ProjectItem piTemp in project.ProjectItems)
{
if (piTemp.Name == _serviceName)
{
mainFolder = piTemp;
}
}
if (mainFolder == null)
{
mainFolder = project.ProjectItems.AddFolder(_serviceName, EnvDTE.Constants.vsProjectItemKindPhysicalFolder);
}
ProjectItem piCommands = null;
foreach (ProjectItem piTemp in mainFolder.ProjectItems)
{
if (piTemp.Name == "Commands")
{
piCommands = piTemp;
break;
}
}
if (piCommands == null)
{
mainFolder.ProjectItems.AddFolder("Commands", EnvDTE.Constants.vsProjectItemKindPhysicalFolder);
}
else
{
// Clean the existing "Commands" directory
foreach (ProjectItem piTemp in piCommands.ProjectItems)
{
piTemp.Delete();
}
}

foreach (Service service in wsdl.Services)
{
string simpleClassName = service.Name;
// Change - If simpleClassName ".cs" exists then CodeTypeFromFullName returns 0 serviceMethods.
// So delete it before we regenerate it.
string strFileName = simpleClassName + ".cs";
foreach (ProjectItem piTemp in mainFolder.ProjectItems)
{
if (piTemp.Name == strFileName)
{
piTemp.Delete();
break;
}
}
CodeType generatedProxyCodeType = project.CodeModel.CodeTypeFromFullName(String.Format("{0}.{1}", nameSpace, simpleClassName));

List<CodeFunction> serviceMethods = GetServiceMethods(operationNames, generatedProxyCodeType);

if (serviceMethods.Count > 0)
{