'Creating SOAP Service from existing WSDL (not consuming)

I need to introduce SOAP services that implements the same contract as a legacy service. All I have is the WSDL.

Can I create server side code from WSDL?

WSDL.exe does not appear to have been ported to Core.

dotnet-svcutil appears to create client code only.

Connected Service feature in VS appear to create client code only.

My best guess so far is to use dotnet-svcutil to create the types and try to write code, that declares similar service and operations and use SoapCore.

Any other options? Does .NET 5 provide a better solution?



Solution 1:[1]

As far as I'm aware there is no tool to generate server side code from a wsdl. You need to recreate those yourself. you can use tooling like xsd.exe or xsd2code to genereate class files for the used types in de wsdl.

If you have those you can specify the service contract with all the required operations and their types.

have a look here for some guidance. https://stackify.com/soap-net-core/

Solution 2:[2]

  1. Use the dotnet-svcutil server.wsdl to generate Reference.cs file. [in order to use the Request Object & Response Object in soap Service which will be created by Soap Core ]

  2. Create Soap Service using soap Core "Install-Package SoapCore" refer to "https://github.com/DigDes/SoapCore" using the interface on the Reference.cs

>>> add a setting like this to appsettings

 "FileWSDL": {
    "UrlOverride": "",
    "WebServiceWSDLMapping": {
      "Service.asmx": {
        "WsdlFile": "snapshotpull.wsdl",
        "SchemaFolder": "Schemas",
        "WsdlFolder": "Schemas"
      }
    },
    "VirtualPath": ""

UrlOverride - can be used to override the URL in the service description. This can be useful if you are behind a firewall.

Service.asmx - is the endpoint of the service you expose. You can have more than one.

WsdlFile - is the name of the WSDL on disc.

SchemaFolder - if you import XSD from WSDL, this is the folder where the Schemas are stored on disc.

WsdlFolder - is the folder that the WSDL file is stored on disc.

VirualPath - can be used if you like to add a path between the base URL and service.

To read the setting you can do the following

In Startup.cs:

var settings = Configuration.GetSection("FileWSDL").Get<WsdlFileOptions>();
settings.AppPath = env.ContentRootPath; // The hosting environment root path
...

app.UseSoapEndpoint<ServiceContractImpl>("/Service.asmx", new SoapEncoderOptions(), SoapSerializer.XmlSerializer, false, null, settings);

I tried and it is working fine on the project, Creating SOAP Service from existing WSDL

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 martijn
Solution 2