Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 744
Soeren Dalby Avatar asked Jan 01 '26 07:01

Soeren Dalby


1 Answers

  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

like image 55
Mohamed Fayek Saber Avatar answered Jan 05 '26 03:01

Mohamed Fayek Saber



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!