Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Use SvcUtil to generate service proxy class.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrward committed Mar 25, 2012
1 parent eb152e3 commit 3358edb
Show file tree
Hide file tree
Showing 23 changed files with 437 additions and 431 deletions.
11 changes: 6 additions & 5 deletions src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
Expand Up @@ -272,28 +272,29 @@
</Compile> </Compile>
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\AdvancedServiceViewModel.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\AdvancedServiceViewModel.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ClientOptions.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ClientOptions.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ICodeDomProvider.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\IFileSystem.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\IFileSystem.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\IProjectWithServiceReferences.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\IProjectWithServiceReferences.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\IServiceReferenceCodeDomBuilder.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\IServiceReferenceFileGenerator.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\IServiceReferenceFileGenerator.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\IServiceReferenceMapGenerator.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\IServiceReferenceMapGenerator.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\IServiceReferenceProxyGenerator.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\IServiceReferenceProxyGenerator.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\MetadataFile.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\MetadataFile.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\MetadataSource.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\MetadataSource.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ProjectWithServiceReferences.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ProjectWithServiceReferences.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceCodeDomBuilder.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceCodeDomProvider.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceFileGenerator.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceFileGenerator.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceFileName.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceFileName.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceFileSystem.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceFileSystem.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceGenerator.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceGenerator.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceGeneratorOptions.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceMapFile.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceMapFile.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceMapFileName.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceMapFileName.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceMapFileProjectItem.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceMapFileProjectItem.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceMapGenerator.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceMapGenerator.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceProxyGenerator.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\ServiceReferenceProxyGenerator.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\WebServiceMetadataSet.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\SvcUtilCommandLine.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\SvcUtilMessageView.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\SvcUtilOptions.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\SvcUtilPath.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReference\SvcUtilRunner.cs" />
<Compile Include="Src\Gui\Dialogs\ToolNotFoundDialog.cs" /> <Compile Include="Src\Gui\Dialogs\ToolNotFoundDialog.cs" />
<Compile Include="Src\Gui\Dialogs\ToolNotFoundDialog.Designer.cs"> <Compile Include="Src\Gui\Dialogs\ToolNotFoundDialog.Designer.cs">
<DependentUpon>ToolNotFoundDialog.cs</DependentUpon> <DependentUpon>ToolNotFoundDialog.cs</DependentUpon>
Expand Down
Expand Up @@ -45,7 +45,6 @@ public class AddServiceReferenceViewModel : ViewModelBase
ServiceDescriptionCollection serviceDescriptionCollection = new ServiceDescriptionCollection(); ServiceDescriptionCollection serviceDescriptionCollection = new ServiceDescriptionCollection();
CredentialCache credentialCache = new CredentialCache(); CredentialCache credentialCache = new CredentialCache();
WebServiceDiscoveryClientProtocol discoveryClientProtocol; WebServiceDiscoveryClientProtocol discoveryClientProtocol;
WebServiceMetadataSet serviceMetadata;


delegate DiscoveryDocument DiscoverAnyAsync(string url); delegate DiscoveryDocument DiscoverAnyAsync(string url);
delegate void DiscoveredWebServicesHandler(DiscoveryClientProtocol protocol); delegate void DiscoveredWebServicesHandler(DiscoveryClientProtocol protocol);
Expand Down Expand Up @@ -225,11 +224,10 @@ void DiscoveredWebServices(DiscoveryClientProtocol protocol)
{ {
if (protocol != null) { if (protocol != null) {
serviceDescriptionCollection = ServiceReferenceHelper.GetServiceDescriptions(protocol); serviceDescriptionCollection = ServiceReferenceHelper.GetServiceDescriptions(protocol);
serviceMetadata = new WebServiceMetadataSet(protocol); ServiceDescriptionMessage = String.Format(

"{0} service(s) found at address {1}",
ServiceDescriptionMessage = String.Format("{0} service(s) found at address {1}", serviceDescriptionCollection.Count,
serviceDescriptionCollection.Count, discoveryUri);
discoveryUri);
DefaultNameSpace = GetDefaultNamespace(); DefaultNameSpace = GetDefaultNamespace();
FillItems(serviceDescriptionCollection); FillItems(serviceDescriptionCollection);
string referenceName = ServiceReferenceHelper.GetReferenceName(discoveryUri); string referenceName = ServiceReferenceHelper.GetReferenceName(discoveryUri);
Expand Down Expand Up @@ -379,8 +377,9 @@ void Add(ServiceDescription description)
public void AddServiceReference() public void AddServiceReference()
{ {
var serviceGenerator = new ServiceReferenceGenerator(project); var serviceGenerator = new ServiceReferenceGenerator(project);
serviceGenerator.Namespace = defaultNameSpace; serviceGenerator.Options.Namespace = defaultNameSpace;
serviceGenerator.AddServiceReference(serviceMetadata); serviceGenerator.Options.Url = discoveryUri.ToString();
serviceGenerator.AddServiceReference();
new RefreshProjectBrowser().Run(); new RefreshProjectBrowser().Run();
} }
} }
Expand Down
Expand Up @@ -8,7 +8,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
public interface IProjectWithServiceReferences public interface IProjectWithServiceReferences
{ {
string ServiceReferencesFolder { get; } string ServiceReferencesFolder { get; }
ICodeDomProvider CodeDomProvider { get; } string Language { get; }


ServiceReferenceFileName GetServiceReferenceFileName(string serviceReferenceName); ServiceReferenceFileName GetServiceReferenceFileName(string serviceReferenceName);
ServiceReferenceMapFileName GetServiceReferenceMapFileName(string serviceReferenceName); ServiceReferenceMapFileName GetServiceReferenceMapFileName(string serviceReferenceName);
Expand Down

This file was deleted.

Expand Up @@ -8,8 +8,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
{ {
public interface IServiceReferenceProxyGenerator public interface IServiceReferenceProxyGenerator
{ {
string ServiceReferenceNamespace { get; set; } ServiceReferenceGeneratorOptions Options { get; }

void GenerateProxyFile();
void GenerateProxyFile(MetadataSet metadata, string proxyFileName);
} }
} }
Expand Up @@ -18,14 +18,8 @@ public class ProjectWithServiceReferences : IProjectWithServiceReferences
public static readonly string DefaultServiceReferencesFolderName = "Service References"; public static readonly string DefaultServiceReferencesFolderName = "Service References";


public ProjectWithServiceReferences(IProject project) public ProjectWithServiceReferences(IProject project)
: this(project, new ServiceReferenceCodeDomProvider(project))
{
}

public ProjectWithServiceReferences(IProject project, ICodeDomProvider codeDomProvider)
{ {
this.project = project; this.project = project;
this.CodeDomProvider = codeDomProvider;
} }


public string ServiceReferencesFolder { public string ServiceReferencesFolder {
Expand All @@ -42,7 +36,9 @@ void GetServiceReferencesFolder()
serviceReferencesFolder = Path.Combine(project.Directory, DefaultServiceReferencesFolderName); serviceReferencesFolder = Path.Combine(project.Directory, DefaultServiceReferencesFolderName);
} }


public ICodeDomProvider CodeDomProvider { get; private set; } public string Language {
get { return project.Language; }
}


public ServiceReferenceFileName GetServiceReferenceFileName(string serviceReferenceName) public ServiceReferenceFileName GetServiceReferenceFileName(string serviceReferenceName)
{ {
Expand Down

This file was deleted.

This file was deleted.

Expand Up @@ -11,9 +11,9 @@ public class ServiceReferenceFileGenerator : IServiceReferenceFileGenerator
IServiceReferenceProxyGenerator proxyGenerator; IServiceReferenceProxyGenerator proxyGenerator;
IServiceReferenceMapGenerator mapGenerator; IServiceReferenceMapGenerator mapGenerator;


public ServiceReferenceFileGenerator(ICodeDomProvider codeDomProvider) public ServiceReferenceFileGenerator()
: this( : this(
new ServiceReferenceProxyGenerator(codeDomProvider), new ServiceReferenceProxyGenerator(),
new ServiceReferenceMapGenerator()) new ServiceReferenceMapGenerator())
{ {
} }
Expand All @@ -26,14 +26,13 @@ public ServiceReferenceFileGenerator(ICodeDomProvider codeDomProvider)
this.mapGenerator = mapGenerator; this.mapGenerator = mapGenerator;
} }


public string ServiceReferenceNamespace { public ServiceReferenceGeneratorOptions Options {
get { return proxyGenerator.ServiceReferenceNamespace; } get { return proxyGenerator.Options; }
set { proxyGenerator.ServiceReferenceNamespace = value; }
} }


public void GenerateProxyFile(MetadataSet metadata, string proxyFileName) public void GenerateProxyFile()
{ {
proxyGenerator.GenerateProxyFile(metadata, proxyFileName); proxyGenerator.GenerateProxyFile();
} }


public void GenerateServiceReferenceMapFile(ServiceReferenceMapFile mapFile) public void GenerateServiceReferenceMapFile(ServiceReferenceMapFile mapFile)
Expand Down
Expand Up @@ -23,7 +23,7 @@ public ServiceReferenceGenerator(IProject project)
public ServiceReferenceGenerator(IProjectWithServiceReferences project) public ServiceReferenceGenerator(IProjectWithServiceReferences project)
: this( : this(
project, project,
new ServiceReferenceFileGenerator(project.CodeDomProvider), new ServiceReferenceFileGenerator(),
new ServiceReferenceFileSystem()) new ServiceReferenceFileSystem())
{ {
} }
Expand All @@ -38,24 +38,27 @@ public ServiceReferenceGenerator(IProjectWithServiceReferences project)
this.fileSystem = fileSystem; this.fileSystem = fileSystem;
} }


public string Namespace { get; set; } public ServiceReferenceGeneratorOptions Options {
get { return fileGenerator.Options; }
}


public void AddServiceReference(MetadataSet metadata) public void AddServiceReference()
{ {
GenerateServiceReferenceProxy(metadata); GenerateServiceReferenceProxy();
project.AddAssemblyReference("System.ServiceModel"); project.AddAssemblyReference("System.ServiceModel");
project.Save(); project.Save();
} }


void GenerateServiceReferenceProxy(MetadataSet metadata) void GenerateServiceReferenceProxy()
{ {
ServiceReferenceFileName referenceFileName = project.GetServiceReferenceFileName(Namespace); ServiceReferenceFileName referenceFileName = project.GetServiceReferenceFileName(fileGenerator.Options.Namespace);
CreateFolderForFileIfFolderMissing(referenceFileName.Path); CreateFolderForFileIfFolderMissing(referenceFileName.Path);


fileGenerator.ServiceReferenceNamespace = Namespace; Options.OutputFileName = referenceFileName.Path;
fileGenerator.GenerateProxyFile(metadata, referenceFileName.Path); Options.MapProjectLanguage(project.Language);
fileGenerator.GenerateProxyFile();


ServiceReferenceMapFileName mapFileName = project.GetServiceReferenceMapFileName(Namespace); ServiceReferenceMapFileName mapFileName = project.GetServiceReferenceMapFileName(fileGenerator.Options.Namespace);
var mapFile = new ServiceReferenceMapFile(mapFileName); var mapFile = new ServiceReferenceMapFile(mapFileName);
fileGenerator.GenerateServiceReferenceMapFile(mapFile); fileGenerator.GenerateServiceReferenceMapFile(mapFile);


Expand Down
@@ -0,0 +1,33 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)

using System;

namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
{
public class ServiceReferenceGeneratorOptions
{
public ServiceReferenceGeneratorOptions()
{
this.OutputFileName = String.Empty;
this.Namespace = String.Empty;
this.Language = "CS";
this.NoAppConfig = true;
}

public string Namespace { get; set; }
public string OutputFileName { get; set; }
public string Url { get; set; }
public string Language { get; set; }
public bool NoAppConfig { get; set; }

public void MapProjectLanguage(string language)
{
if (language == "VBNet") {
Language = "VB";
} else {
Language = "CS";
}
}
}
}
Expand Up @@ -9,37 +9,17 @@
namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
{ {
public class ServiceReferenceProxyGenerator : IServiceReferenceProxyGenerator public class ServiceReferenceProxyGenerator : IServiceReferenceProxyGenerator
{ {
IServiceReferenceCodeDomBuilder codeDomBuilder; SvcUtilOptions options = new SvcUtilOptions();
ICodeDomProvider codeDomProvider;


public ServiceReferenceProxyGenerator(ICodeDomProvider codeDomProvider) public ServiceReferenceGeneratorOptions Options {
: this(codeDomProvider, new ServiceReferenceCodeDomBuilder()) get { return options; }
{
}

public ServiceReferenceProxyGenerator(
ICodeDomProvider codeDomProvider,
IServiceReferenceCodeDomBuilder codeDomBuilder)
{
this.codeDomProvider = codeDomProvider;
this.codeDomBuilder = codeDomBuilder;
}

public string ServiceReferenceNamespace {
get { return codeDomBuilder.Namespace; }
set { codeDomBuilder.Namespace = value; }
}

public void GenerateProxyFile(MetadataSet metadata, string proxyFileName)
{
CodeCompileUnit compileUnit = codeDomBuilder.GenerateCompileUnit(metadata);
GenerateProxy(compileUnit, proxyFileName);
} }


void GenerateProxy(CodeCompileUnit compileUnit, string fileName) public void GenerateProxyFile()
{ {
codeDomProvider.GenerateCodeFromCompileUnit(compileUnit, fileName); var runner = new SvcUtilRunner(options);
runner.Run();
} }
} }
} }

0 comments on commit 3358edb

Please sign in to comment.