Permalink
Browse files

Use SvcUtil to generate service proxy class.

  • Loading branch information...
1 parent eb152e3 commit 3358edbaa0dcd612df107b93d3575d9596429be5 @mrward mrward committed Mar 25, 2012
Showing with 437 additions and 431 deletions.
  1. +6 −5 src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  2. +7 −8 ...ain/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AddServiceReferenceViewModel.cs
  3. +1 −1 ...in/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IProjectWithServiceReferences.cs
  4. +0 −15 .../Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IServiceReferenceCodeDomBuilder.cs
  5. +2 −3 .../Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/IServiceReferenceProxyGenerator.cs
  6. +3 −7 ...ain/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ProjectWithServiceReferences.cs
  7. +0 −53 ...n/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceCodeDomBuilder.cs
  8. +0 −42 .../Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceCodeDomProvider.cs
  9. +6 −7 ...in/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceFileGenerator.cs
  10. +12 −9 src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGenerator.cs
  11. +33 −0 ...Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceGeneratorOptions.cs
  12. +7 −27 ...n/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/ServiceReferenceProxyGenerator.cs
  13. +85 −0 src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilCommandLine.cs
  14. +31 −0 src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilMessageView.cs
  15. +11 −4 ...roject/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/{ICodeDomProvider.cs → SvcUtilOptions.cs}
  16. +63 −0 src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilPath.cs
  17. +65 −0 src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/SvcUtilRunner.cs
  18. +0 −50 src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/WebServiceMetadataSet.cs
  19. +0 −2 src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj
  20. +23 −13 src/Main/Base/Test/ServiceReferences/ProjectWithServiceReferencesTests.cs
  21. +82 −24 src/Main/Base/Test/ServiceReferences/ServiceReferenceGeneratorTests.cs
  22. +0 −64 src/Main/Base/Test/ServiceReferences/ServiceReferenceProxyGeneratorTests.cs
  23. +0 −97 src/Main/Base/Test/ServiceReferences/WebServiceMetadataSetTests.cs
@@ -272,28 +272,29 @@
</Compile>
<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\ICodeDomProvider.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\IServiceReferenceCodeDomBuilder.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\IServiceReferenceProxyGenerator.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\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\ServiceReferenceFileName.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\ServiceReferenceGeneratorOptions.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\ServiceReferenceMapFileProjectItem.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\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.Designer.cs">
<DependentUpon>ToolNotFoundDialog.cs</DependentUpon>
@@ -45,7 +45,6 @@ public class AddServiceReferenceViewModel : ViewModelBase
ServiceDescriptionCollection serviceDescriptionCollection = new ServiceDescriptionCollection();
CredentialCache credentialCache = new CredentialCache();
WebServiceDiscoveryClientProtocol discoveryClientProtocol;
- WebServiceMetadataSet serviceMetadata;
delegate DiscoveryDocument DiscoverAnyAsync(string url);
delegate void DiscoveredWebServicesHandler(DiscoveryClientProtocol protocol);
@@ -225,11 +224,10 @@ void DiscoveredWebServices(DiscoveryClientProtocol protocol)
{
if (protocol != null) {
serviceDescriptionCollection = ServiceReferenceHelper.GetServiceDescriptions(protocol);
- serviceMetadata = new WebServiceMetadataSet(protocol);
-
- ServiceDescriptionMessage = String.Format("{0} service(s) found at address {1}",
- serviceDescriptionCollection.Count,
- discoveryUri);
+ ServiceDescriptionMessage = String.Format(
+ "{0} service(s) found at address {1}",
+ serviceDescriptionCollection.Count,
+ discoveryUri);
DefaultNameSpace = GetDefaultNamespace();
FillItems(serviceDescriptionCollection);
string referenceName = ServiceReferenceHelper.GetReferenceName(discoveryUri);
@@ -379,8 +377,9 @@ void Add(ServiceDescription description)
public void AddServiceReference()
{
var serviceGenerator = new ServiceReferenceGenerator(project);
- serviceGenerator.Namespace = defaultNameSpace;
- serviceGenerator.AddServiceReference(serviceMetadata);
+ serviceGenerator.Options.Namespace = defaultNameSpace;
+ serviceGenerator.Options.Url = discoveryUri.ToString();
+ serviceGenerator.AddServiceReference();
new RefreshProjectBrowser().Run();
}
}
@@ -8,7 +8,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
public interface IProjectWithServiceReferences
{
string ServiceReferencesFolder { get; }
- ICodeDomProvider CodeDomProvider { get; }
+ string Language { get; }
ServiceReferenceFileName GetServiceReferenceFileName(string serviceReferenceName);
ServiceReferenceMapFileName GetServiceReferenceMapFileName(string serviceReferenceName);
@@ -1,15 +0,0 @@
-// 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;
-using System.CodeDom;
-using System.ServiceModel.Description;
-
-namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
-{
- public interface IServiceReferenceCodeDomBuilder
- {
- string Namespace { get; set; }
- CodeCompileUnit GenerateCompileUnit(MetadataSet metadata);
- }
-}
@@ -8,8 +8,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
{
public interface IServiceReferenceProxyGenerator
{
- string ServiceReferenceNamespace { get; set; }
-
- void GenerateProxyFile(MetadataSet metadata, string proxyFileName);
+ ServiceReferenceGeneratorOptions Options { get; }
+ void GenerateProxyFile();
}
}
@@ -18,14 +18,8 @@ public class ProjectWithServiceReferences : IProjectWithServiceReferences
public static readonly string DefaultServiceReferencesFolderName = "Service References";
public ProjectWithServiceReferences(IProject project)
- : this(project, new ServiceReferenceCodeDomProvider(project))
- {
- }
-
- public ProjectWithServiceReferences(IProject project, ICodeDomProvider codeDomProvider)
{
this.project = project;
- this.CodeDomProvider = codeDomProvider;
}
public string ServiceReferencesFolder {
@@ -42,7 +36,9 @@ void GetServiceReferencesFolder()
serviceReferencesFolder = Path.Combine(project.Directory, DefaultServiceReferencesFolderName);
}
- public ICodeDomProvider CodeDomProvider { get; private set; }
+ public string Language {
+ get { return project.Language; }
+ }
public ServiceReferenceFileName GetServiceReferenceFileName(string serviceReferenceName)
{
@@ -1,53 +0,0 @@
-// 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;
-using System.CodeDom;
-using System.Runtime.Serialization;
-using System.ServiceModel.Channels;
-using System.ServiceModel.Description;
-
-namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
-{
- public class ServiceReferenceCodeDomBuilder : IServiceReferenceCodeDomBuilder
- {
- public ServiceReferenceCodeDomBuilder()
- {
- this.Namespace = String.Empty;
- }
-
- public string Namespace { get; set; }
-
- public CodeCompileUnit GenerateCompileUnit(MetadataSet metadata)
- {
- ServiceContractGenerator contractGenerator = CreateServiceContractGenerator();
- WsdlImporter importer = CreateWsdlImporter(metadata);
-
- foreach (ContractDescription contract in importer.ImportAllContracts()) {
- contractGenerator.GenerateServiceContractType(contract);
- }
-
- return contractGenerator.TargetCompileUnit;
- }
-
- WsdlImporter CreateWsdlImporter(MetadataSet metadata)
- {
- var importer = new WsdlImporter(metadata);
- var contractImporter = new XsdDataContractImporter();
- contractImporter.Options = new ImportOptions();
- contractImporter.Options.Namespaces.Add("*", Namespace);
- importer.State.Add(typeof(XsdDataContractImporter), contractImporter);
- return importer;
- }
-
- ServiceContractGenerator CreateServiceContractGenerator()
- {
- var contractGenerator = new ServiceContractGenerator();
- contractGenerator.Options =
- ServiceContractGenerationOptions.ClientClass |
- ServiceContractGenerationOptions.ChannelInterface;
- contractGenerator.NamespaceMappings.Add("*", Namespace);
- return contractGenerator;
- }
- }
-}
@@ -1,42 +0,0 @@
-// 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;
-using System.CodeDom;
-using System.CodeDom.Compiler;
-using System.IO;
-using ICSharpCode.SharpDevelop.Project;
-
-namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
-{
- public class ServiceReferenceCodeDomProvider : ICodeDomProvider
- {
- IProject project;
- CodeDomProvider codeDomProvider;
-
- public ServiceReferenceCodeDomProvider(IProject project)
- {
- this.project = project;
- }
-
- public string FileExtension {
- get { return CodeDomProvider.FileExtension; }
- }
-
- CodeDomProvider CodeDomProvider {
- get {
- if (codeDomProvider == null) {
- codeDomProvider = project.LanguageProperties.CodeDomProvider;
- }
- return codeDomProvider;
- }
- }
-
- public void GenerateCodeFromCompileUnit(CodeCompileUnit compileUnit, string fileName)
- {
- using (var writer = new StreamWriter(fileName)) {
- CodeDomProvider.GenerateCodeFromCompileUnit(compileUnit, writer, null);
- }
- }
- }
-}
@@ -11,9 +11,9 @@ public class ServiceReferenceFileGenerator : IServiceReferenceFileGenerator
IServiceReferenceProxyGenerator proxyGenerator;
IServiceReferenceMapGenerator mapGenerator;
- public ServiceReferenceFileGenerator(ICodeDomProvider codeDomProvider)
+ public ServiceReferenceFileGenerator()
: this(
- new ServiceReferenceProxyGenerator(codeDomProvider),
+ new ServiceReferenceProxyGenerator(),
new ServiceReferenceMapGenerator())
{
}
@@ -26,14 +26,13 @@ public ServiceReferenceFileGenerator(ICodeDomProvider codeDomProvider)
this.mapGenerator = mapGenerator;
}
- public string ServiceReferenceNamespace {
- get { return proxyGenerator.ServiceReferenceNamespace; }
- set { proxyGenerator.ServiceReferenceNamespace = value; }
+ public ServiceReferenceGeneratorOptions Options {
+ get { return proxyGenerator.Options; }
}
- public void GenerateProxyFile(MetadataSet metadata, string proxyFileName)
+ public void GenerateProxyFile()
{
- proxyGenerator.GenerateProxyFile(metadata, proxyFileName);
+ proxyGenerator.GenerateProxyFile();
}
public void GenerateServiceReferenceMapFile(ServiceReferenceMapFile mapFile)
@@ -23,7 +23,7 @@ public ServiceReferenceGenerator(IProject project)
public ServiceReferenceGenerator(IProjectWithServiceReferences project)
: this(
project,
- new ServiceReferenceFileGenerator(project.CodeDomProvider),
+ new ServiceReferenceFileGenerator(),
new ServiceReferenceFileSystem())
{
}
@@ -38,24 +38,27 @@ public ServiceReferenceGenerator(IProjectWithServiceReferences project)
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.Save();
}
- void GenerateServiceReferenceProxy(MetadataSet metadata)
+ void GenerateServiceReferenceProxy()
{
- ServiceReferenceFileName referenceFileName = project.GetServiceReferenceFileName(Namespace);
+ ServiceReferenceFileName referenceFileName = project.GetServiceReferenceFileName(fileGenerator.Options.Namespace);
CreateFolderForFileIfFolderMissing(referenceFileName.Path);
- fileGenerator.ServiceReferenceNamespace = Namespace;
- fileGenerator.GenerateProxyFile(metadata, referenceFileName.Path);
+ Options.OutputFileName = 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);
fileGenerator.GenerateServiceReferenceMapFile(mapFile);
@@ -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";
+ }
+ }
+ }
+}
@@ -9,37 +9,17 @@
namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
{
public class ServiceReferenceProxyGenerator : IServiceReferenceProxyGenerator
- {
- IServiceReferenceCodeDomBuilder codeDomBuilder;
- ICodeDomProvider codeDomProvider;
+ {
+ SvcUtilOptions options = new SvcUtilOptions();
- public ServiceReferenceProxyGenerator(ICodeDomProvider codeDomProvider)
- : this(codeDomProvider, new ServiceReferenceCodeDomBuilder())
- {
- }
-
- 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);
+ public ServiceReferenceGeneratorOptions Options {
+ get { return options; }
}
- void GenerateProxy(CodeCompileUnit compileUnit, string fileName)
+ public void GenerateProxyFile()
{
- codeDomProvider.GenerateCodeFromCompileUnit(compileUnit, fileName);
+ var runner = new SvcUtilRunner(options);
+ runner.Run();
}
}
}
Oops, something went wrong.

0 comments on commit 3358edb

Please sign in to comment.