Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/dotnet-svcutil/lib/src/CodeDomFixup/VisitorFixup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ internal class VisitorFixup : CodeFixup
{
private static CodeDomVisitor[] GetVisitors(ServiceContractGenerator generator, CommandProcessorOptions options)
{
ArrayOfXElementTypeHelper arrayOfXElementTypeHelper = new ArrayOfXElementTypeHelper((generator.Options & ServiceContractGenerationOptions.InternalTypes) == ServiceContractGenerationOptions.InternalTypes, generator.TargetCompileUnit);
// Keep the ArrayOfXElement helper public even under --internal.
// WCF's XmlSerializer operation behavior generates serializer assemblies at runtime; those assemblies cannot
// reference internal types, so internal schema/message types can fail at runtime. Keeping this helper public
// avoids inconsistent accessibility without breaking XmlSerializer runtime behavior.
ArrayOfXElementTypeHelper arrayOfXElementTypeHelper = new ArrayOfXElementTypeHelper(isInternal: false, generator.TargetCompileUnit);
bool isVisualBasic = IsVisualBasicLanguage(options?.Language);

CodeDomVisitor[] visitors = new CodeDomVisitor[]
Expand Down
54 changes: 51 additions & 3 deletions src/dotnet-svcutil/lib/src/ImportModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Linq;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Threading;

using DcNS = System.Runtime.Serialization;
using WsdlNS = System.Web.Services.Description;
Expand All @@ -24,6 +25,8 @@ namespace Microsoft.Tools.ServiceModel.Svcutil
{
internal partial class ImportModule
{
private static int s_internalWithXmlSerializerWarningEmitted;

private readonly CodeCompileUnit _codeCompileUnit;
private readonly WsdlImporter _wsdlImporter;
private readonly ServiceContractGenerator _contractGenerator;
Expand Down Expand Up @@ -125,6 +128,11 @@ public bool AfterImportMetadata(ServiceDescriptor serviceDescriptor)
{
try
{
if (_options.InternalTypeAccess == true && UsesXmlSerializer(serviceDescriptor, _options))
{
EmitInternalWithXmlSerializerWarningOnce();
}

// Convert errors to warnings to workaround the issue that many validation errors from XSD compiler
// can be ignored.
for (int idx = _wsdlImporter.Errors.Count - 1; idx >= _nonWsdlImportErrors; idx--)
Expand Down Expand Up @@ -176,6 +184,46 @@ public bool AfterImportMetadata(ServiceDescriptor serviceDescriptor)
return contractsResolved;
}

private static bool UsesXmlSerializer(ServiceDescriptor serviceDescriptor, CommandProcessorOptions options)
{
if (options?.SerializerMode == SerializerMode.XmlSerializer)
{
return true;
}

if (serviceDescriptor?.Contracts == null)
{
return false;
}

foreach (ContractDescription contract in serviceDescriptor.Contracts)
{
if (contract?.Operations == null)
{
continue;
}

foreach (OperationDescription operation in contract.Operations)
{
// Presence of this behavior indicates the operation will use XmlSerializer at runtime.
if (operation?.Behaviors?.Find<XmlSerializerOperationBehavior>() != null)
{
return true;
}
}
}

return false;
}

private static void EmitInternalWithXmlSerializerWarningOnce()
{
if (Interlocked.Exchange(ref s_internalWithXmlSerializerWarningEmitted, 1) == 0)
{
ToolConsole.WriteWarning(SR.WrnInternalOptionPartiallyAppliedWithXmlSerializer);
}
}

private static bool ContractsResolved(ServiceDescriptor serviceDescriptor, CodeCompileUnit codeCompileUnit)
{
if (serviceDescriptor != null && codeCompileUnit != null)
Expand Down Expand Up @@ -339,9 +387,9 @@ private static void AddStateForXmlSerializerImport(CommandProcessorOptions optio
if (options.EnableDataBinding == true)
importOptions.WebReferenceOptions.CodeGenerationOptions |= CodeGenerationOptions.EnableDataBinding;

// Right now System.Data API not available in DNX. If it comes available we could consider uncommenting these.
// importOptions.WebReferenceOptions.SchemaImporterExtensions.Add(typeof(TypedDataSetSchemaImporterExtensionFx35).AssemblyQualifiedName);
// importOptions.WebReferenceOptions.SchemaImporterExtensions.Add(typeof(DataSetSchemaImporterExtension).AssemblyQualifiedName);
// Enable a minimal schema importer extension for DataSet/DataTable.
// This avoids generating placeholder IXmlSerializable + ArrayOfXElement types for common DataSet wrapper patterns.
importOptions.WebReferenceOptions.SchemaImporterExtensions.Add(typeof(DataSetSchemaImporterExtension).AssemblyQualifiedName);

importOptions.CodeProvider = options.CodeProvider;

Expand Down
3 changes: 3 additions & 0 deletions src/dotnet-svcutil/lib/src/SR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,9 @@ Your credentials will be sent to the server in clear text.</value>
<data name="WrnCouldNotGenerateContractOperationsFormat" xml:space="preserve">
<value>Could not generate contract operations using the '{0}' type, attempting with the '{1}' type.</value>
</data>
<data name="WrnInternalOptionPartiallyAppliedWithXmlSerializer" xml:space="preserve">
<value>--internal may be only partially applied when using XmlSerializer; some schema wrapper types are generated as public for runtime compatibility.</value>
</data>
<data name="TelemetryEnabled" xml:space="preserve">
<value>This tool collects information about how it is used in order to improve the tool. This functionality can be disabled by setting the environment variable "DOTNET_SVCUTIL_TELEMETRY_OPTOUT" to 1.
</value>
Expand Down
Loading
Loading