dotnet-svcutil. The XmlSerializer nuget package can be NET Core project pre generates serialized assemblies. It pre generates C# serialization code for types in client applications that are used by WCF service contracts and can be serialized by XmlSerializer. This improves the startup performance of XML serialization when serializing or deserializing objects of these types.
precondition
. NET Core 2.1 SDK or later
Your favorite code editor
You can use the command dotnet --info to check which versions are installed NET SDK and runtime.
introduction
Yes NET Core console application using dotnet svcutil xmlserializer:
Yes NET Framework uses the default template "WCF service application" to create a WCF service named "MyWCFService". Add the [XmlSerializerFormat] attribute on the service method as follows:
[ServiceContract] public interface IService1 { [XmlSerializerFormat] [OperationContract(Action = "http://tempuri.org/IService1/GetData", ReplyAction = "http://tempuri.org/IService1/GetDataResponse")] string GetData(int value); }
establish. NET Core console application as object - oriented NET Core 2.1 or later WCF client application. For example, use the following command to create an app named "mywcfcclient":
dotnet new console --name MyWCFClient
Make sure the project is oriented NET Core 2.1 or later, check the TargetFramework XML element in the project file:
<TargetFramework>netcoreapp2.1</TargetFramework>
Add a package reference to the system. Net by running the following command ServiceModel. Http:
dotnet add package System.ServiceModel.Http
Add WCF client code:
using System.ServiceModel; class Program { static void Main(string[] args) { var myBinding = new BasicHttpBinding(); var myEndpoint = new EndpointAddress("http://localhost:2561/Service1.svc"); //Fill your service url here var myChannelFactory = new ChannelFactory<IService1>(myBinding, myEndpoint); IService1 client = myChannelFactory.CreateChannel(); string s = client.GetData(1); ((ICommunicationObject)client).Close(); } } [ServiceContract] public interface IService1 { [XmlSerializerFormat] [OperationContract(Action = "http://tempuri.org/IService1/GetData", ReplyAction = "http://tempuri.org/IService1/GetDataResponse")] string GetData(int value); }
Add the reference to dotnet svcutil. Exe by running the following command XmlSerializer package:
dotnet add package dotnet-svcutil.xmlserializer
Running this command should add an entry similar to the following to the project file:
<ItemGroup> <DotNetCliToolReference Include="dotnet-svcutil.xmlserializer" Version="1.0.0" /> </ItemGroup>
Generate the application by running dotnet build. If all goes well, an assembly named "mywcfcclient. Xmlserializers. DLL" will be generated in the output folder. If the tool cannot build the assembly, you will see a warning in the build output.
For example, by running in a browser http://localhost:2561/Service1.svc To start the WCF service. Then start the client application, which will automatically load and use the pre generated serializer at run time.