Wcf: svcutil for Xml Serialization

Created on 30 Jun 2016  路  15Comments  路  Source: dotnet/wcf

Anything on the roadmap for WCF Connected Services to have a svcutil.exe /t:xmlSerializer type option to generate XmlSerializer serialization code instead of doing it at runtime?

feature request serialization

Most helpful comment

We've updated our SOAP library with dotnet-svcutil.xmlserializer package, and so far everything looks great. At run time the pregenerated XmlSerializers is used, which gets us a huge start up time increase.

If anyone is packaging this up into a nuget package we used <BuildOutputInPackage Include="$(OutputPath)$(AssemblyName).XmlSerializers.dll" /> to get the *.XmlSerializers.dll to be included along with the main project output.

Complete *.csproj as example.

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>netstandard2.0</TargetFrameworks>
    <TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);IncludeXmlSerializers</TargetsForTfmSpecificBuildOutput>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="dotnet-svcutil.xmlserializer" Version="1.0.0-preview1" />
    <PackageReference Include="System.ServiceModel.Duplex" Version="4.4.*" />
    <PackageReference Include="System.ServiceModel.Http" Version="4.5.0" />
    <PackageReference Include="System.ServiceModel.NetTcp" Version="4.4.*" />
    <PackageReference Include="System.ServiceModel.Security" Version="4.4.*" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="dotnet-svcutil.xmlserializer" Version="1.0.0-preview1" />
  </ItemGroup>
  <Target Name="IncludeXmlSerializers">
    <ItemGroup>
      <BuildOutputInPackage Include="$(OutputPath)$(AssemblyName).XmlSerializers.dll" />
    </ItemGroup>
  </Target>
</Project>

All 15 comments

@zhenlan Is there a way to mechanically transform the serializer code generated by the original svcutil to .NET Core compatible code? E.g. I have this service and the corresponding serializers file generated using the svcutil /t:xmlSerializers flag. Would it be possible to tweak this in some way so it works in a .NET Standard class library?

@masaeedu I see no better way other than trying to fix up the code (generated by desktop svcutil) manually by compiling it against .NET Core. But this is just the first half of the story - for the pre-generated serializers to be used, the serialization runtime has to be updated to be aware of them and use them. This second half is not yet present in .NET Core.

cc: @shmao @huanwu

@zhenlan I've been trying to make this work. One of the things I'm stuck with is the lack of an obvious parallel to XmlSerializationWriter and XmlSerializationReader. There's XmlReader and XmlWriter, but the API seems too different to port easily, and the the XmlSerialization____ classes aren't very well documented because they were supposed to be internal APIs. If we can find 1-1 replacements for all the XmlSerializationReader/Writer stuff in the old svcutil codegen for the serializers assembly, we should be able to repurpose it to run on .NET Core.

@masaeedu XmlSerializationWriter and XmlSerializationReader have been added in dotnet/corefx. And they would be available in .Net Core 2.0. To try .Net Core 2.0, which is not released yet, you may want to have a look at How to get up and running on .NET Core 2.0.

This issue and #1510 are currently pending dotnet/corefx#4561.

As the third party is not fully WS* compliant, svcutil falls back to XMLSerializer. The root cause was, the proxy is that large, creating of the channel takes 5 seconds. With datacontract just 20 ms. I have more infos if wanted which I can share only via email. Thanks :-)

I am happy to announce that we just had an XmlSerializer pre-generator tool for WCF, named dotnet-svcutil.xmlserializer released today. Please see details and instructions in the announcement. The NuGet package can be found at https://www.nuget.org/packages/dotnet-svcutil.xmlserializer/.

We will appreciate any feedback you may share with us.

@zhenlan Thank you for the release, we're excited to use this!

Is there a verbose/trace switch to see more info on failures?

Restore completed in 47.6 ms for C:\Users\jherbert\Projects\ReplacementProject\src\ReplacementProject\ReplacementProject.csproj.
  ReplacementProject -> C:\Users\jherbert\Projects\ReplacementProject\src\ReplacementProject\bin\Debug\netstandard2.0\ReplacementProject.dll
  No executable found matching command "dotnet-svcutil.xmlserializer"
C:\Users\jherbert\.nuget\packages\dotnet-svcutil.xmlserializer\1.0.0-preview1\build\dotnet-svcutil.xmlserializer.targets(17,5): warning MSB3073: The command "dotnet svcutil.xmlserializer obj\Debug\netstandard2.0\ReplacementProject.dll /out:obj\Debug\netstandard2.0\ReplacementProject.XmlSerializers" exited with code 1. [C:\Users\jherbert\Projects\ReplacementProject\src\ReplacementProject\ReplacementProject.csproj]
C:\Users\jherbert\.nuget\packages\dotnet-svcutil.xmlserializer\1.0.0-preview1\build\dotnet-svcutil.xmlserializer.targets(18,5): warning : Warning : Fail to generate the serializer for
ReplacementProject.dll. [C:\Users\jherbert\Projects\ReplacementProject\src\ReplacementProject\ReplacementProject.csproj]

*.csproj looks like

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>netstandard2.0</TargetFrameworks>
    <VersionPrefix>1.2017.1</VersionPrefix>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="dotnet-svcutil.xmlserializer" Version="1.0.0-preview1" />
    <PackageReference Include="System.ServiceModel.Duplex" Version="4.4.*" />
    <PackageReference Include="System.ServiceModel.Http" Version="4.5.0" />
    <PackageReference Include="System.ServiceModel.NetTcp" Version="4.4.*" />
    <PackageReference Include="System.ServiceModel.Security" Version="4.4.*" />
  </ItemGroup>
</Project>

with a single auto generated *.cs from svcutil wsdl import.

Never mind was missing

  <ItemGroup>
    <DotNetCliToolReference Include="dotnet-svcutil.xmlserializer" Version="1.0.0-preview1" />
  </ItemGroup>

馃檨

We've updated our SOAP library with dotnet-svcutil.xmlserializer package, and so far everything looks great. At run time the pregenerated XmlSerializers is used, which gets us a huge start up time increase.

If anyone is packaging this up into a nuget package we used <BuildOutputInPackage Include="$(OutputPath)$(AssemblyName).XmlSerializers.dll" /> to get the *.XmlSerializers.dll to be included along with the main project output.

Complete *.csproj as example.

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>netstandard2.0</TargetFrameworks>
    <TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);IncludeXmlSerializers</TargetsForTfmSpecificBuildOutput>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="dotnet-svcutil.xmlserializer" Version="1.0.0-preview1" />
    <PackageReference Include="System.ServiceModel.Duplex" Version="4.4.*" />
    <PackageReference Include="System.ServiceModel.Http" Version="4.5.0" />
    <PackageReference Include="System.ServiceModel.NetTcp" Version="4.4.*" />
    <PackageReference Include="System.ServiceModel.Security" Version="4.4.*" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="dotnet-svcutil.xmlserializer" Version="1.0.0-preview1" />
  </ItemGroup>
  <Target Name="IncludeXmlSerializers">
    <ItemGroup>
      <BuildOutputInPackage Include="$(OutputPath)$(AssemblyName).XmlSerializers.dll" />
    </ItemGroup>
  </Target>
</Project>

I am facing issues using dotnet-svcutil.xmlserializer

  1. When added reference to the existing project already referencing System.ServiceModel.Http 4.5.1 it was complaining about not being able to find System.ServiceModel.Primitives 4.5.0.
    Downgrading to System.ServiceModel.Http 4.5.0 did not help. Only when removing System.ServiceModel.Http and adding back version 4.5.0 the tool generated XmlSerializers.dll (locally on Windows).
  2. Apart from that it still complains:
    Microsoft (R) Service Model Metadata Tool\r\n[Microsoft (R) Windows (R) Communication Foundation, Version 1.0.0-preview1]\r\nCopyright (c) Microsoft Corporation. All rights reserved.\r\n
    Generating XML serializers...
    EXEC : warning : There were errors loading types in an assembly loaded from '.dll' some types in the assembly could not be loaded and will not be available to the tool. [.csproj]

Could not load file or assembly 'Swashbuckle.AspNetCore.Examples, Version=2.9.0.0, Culture=neutral, PublicKeyToken=aa1e9c5053bfbe95'. The system cannot find the file specified.
Could not load file or assembly 'Swashbuckle.AspNetCore.Examples, Version=2.9.0.0, Culture=neutral, PublicKeyToken=aa1e9c5053bfbe95'. The system cannot find the file specified.
Could not load file or assembly 'Swashbuckle.AspNetCore.Examples, Version=2.9.0.0, Culture=neutral, PublicKeyToken=aa1e9c5053bfbe95'. The system cannot find the file specified.
Could not load file or assembly 'Swashbuckle.AspNetCore.Examples, Version=2.9.0.0, Culture=neutral, PublicKeyToken=aa1e9c5053bfbe95'. The system cannot find the file specified.
Could not load file or assembly 'Swashbuckle.AspNetCore.Examples, Version=2.9.0.0, Culture=neutral, PublicKeyToken=aa1e9c5053bfbe95'. The system cannot find the file specified.
Could not load file or assembly 'Swashbuckle.AspNetCore.Examples, Version=2.9.0.0, Culture=neutral, PublicKeyToken=aa1e9c5053bfbe95'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Core, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Could not load file or assembly 'Swashbuckle.AspNetCore.SwaggerGen, Version=2.5.0.0, Culture=neutral, PublicKeyToken=d84d99fb0135530a'. The system cannot find the file specified.
Could not load file or assembly 'Swashbuckle.AspNetCore.SwaggerGen, Version=2.5.0.0, Culture=neutral, PublicKeyToken=d84d99fb0135530a'. The system cannot find the file specified.
Could not load file or assembly 'Swashbuckle.AspNetCore.SwaggerGen, Version=2.5.0.0, Culture=neutral, PublicKeyToken=d84d99fb0135530a'. The system cannot find the file specified.
Could not load file or assembly 'Swashbuckle.AspNetCore.SwaggerGen, Version=2.5.0.0, Culture=neutral, PublicKeyToken=d84d99fb0135530a'. The system cannot find the file specified.
Could not load file or assembly 'Swashbuckle.AspNetCore.SwaggerGen, Version=2.5.0.0, Culture=neutral, PublicKeyToken=d84d99fb0135530a'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Core, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Core, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Could not load file or assembly 'StatsdClient, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Abstractions, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Abstractions, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Abstractions, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Abstractions, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Abstractions, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Abstractions, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Abstractions, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Abstractions, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
*.XmlSerializers.cs

One thing is why it cannot load these assemblies but other is why it even attempts to load them?

  1. On the build agent (running Ubuntu) the tool fails to generate XmlSerializers.dll altogether, showing the same list of assemblies it cannot load but also

[16:00:09][Step 1/4] ci-build_1 | /src/src//.\/obj/Release/netcoreapp2.1/.XmlSerializers.cs
[16:00:09][Step 1/4] ci-build_1 | /root/.nuget/packages/dotnet-svcutil.xmlserializer/1.0.0-preview1/build/dotnet-svcutil.xmlserializer.targets(18,5): warning : Warning : Fail to generate the serializer for .dll. [/src/src/.csproj]

It is hard to guess what it does not like this time, what I do not like is that it seem to mix up two types of slashes in the first message.

Does anybody know any way around these issues?
Thanks!

@rafsojka Could you try the latest stable version and see if it works?

@huanwu thanks, I am struggling to find a time to verify.
Will post an update once I get down to that.

@rafsojka Closing the issue. Please let us know if you still have problem.

Was this page helpful?
0 / 5 - 0 ratings