Skip to content

Latest commit

 

History

History

README.md

SmartWsdlKit.SourceGenerators

NuGet Version License

SmartWsdlKit.SourceGenerators is a high-performance Roslyn Incremental Source Generator package for the SmartWsdlKit SDK.

It automatically parses local WSDL files at compile-time and generates strongly-typed, modern C# SOAP client proxies, service interfaces, and DTO record models. This eliminates legacy Visual Studio Connected Services, svcutil command line tools, and dynamic runtime reflection overhead completely.


Key Benefits

  • Zero Runtime Reflection: All XML serialization and method mapping logic is generated during compilation for maximum throughput.
  • Instant IDE IntelliSense: Generated proxies are available immediately in your IDE as soon as you save your .wsdl file.
  • Compile-Time Safety & Diagnostics: If the service contract changes or the WSDL is malformed, compiler warnings (SWK001) are reported directly in your build output or IDE error list.
  • Modern C# Code Output: Generates immutable C# 9.0 record types for DTOs and clean async interfaces.

Installation

Add both the core runtime package (SmartWsdlKit) and the source generator package (SmartWsdlKit.SourceGenerators) to your project:

dotnet add package SmartWsdlKit
dotnet add package SmartWsdlKit.SourceGenerators

Setup & Configuration

1. Add your WSDL File

Place your WSDL file (e.g., Calculator.wsdl or CountryInfo.wsdl.xml) in your project directory (e.g., under a Wsdl/ folder).

2. Register WSDL as AdditionalFiles in .csproj

Edit your .csproj file and add the WSDL file inside an <ItemGroup> using the <AdditionalFiles> build action:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
  </PropertyGroup>

  <!-- Core Runtime & Generator References -->
  <ItemGroup>
    <PackageReference Include="SmartWsdlKit" Version="1.0.3" />
    <PackageReference Include="SmartWsdlKit.SourceGenerators" Version="1.0.3" PrivateAssets="all" />
  </ItemGroup>

  <!-- Register WSDL files for Compile-Time Code Generation -->
  <ItemGroup>
    <AdditionalFiles Include="Wsdl/Calculator.wsdl" />
  </ItemGroup>

</Project>

3. Build Project

When you build your project (dotnet build), Roslyn will execute the generator and output generated proxy classes under the SmartWsdlKit.Generated namespace.


Consumption Example

using System;
using System.Threading.Tasks;
using SmartWsdlKit;
using SmartWsdlKit.Generated; // Generated namespace containing DTO records & clients

class Program
{
    static async Task Main()
    {
        var options = new SoapClientOptions
        {
            BaseAddress = new Uri("http://www.dneonline.com/calculator.asmx"),
            Timeout = TimeSpan.FromSeconds(10),
            EnableDiagnostics = true
        };

        // Instantiating the generated client proxy
        using var client = new CalculatorSoapClient(options);

        // Invoking the strongly-typed generated operation
        var response = await client.AddAsync(new AddRequest
        {
            intA = 100,
            intB = 250
        });

        Console.WriteLine($"Calculated Result: {response.AddResult}"); // Outputs: 350
    }
}

Diagnostic Rules

The generator analyzes WSDL structures during compilation and reports validation issues directly to the compiler output:

Diagnostic ID Severity Title Description
SWK001 Warning WSDL Parsing Failed Reported when a registered WSDL file is malformed, cannot be read, or imports cannot be resolved.

License

This project is licensed under the MIT License.