I'm using SoapCore (SOAP protocol middleware for ASP.NET Core) to create a Soap Server using an existing soap file (.WSDL) on my local machine.
I'm using the following configuration in appsettings.json:
"FileWSDL":
{
"UrlOverride": "/Service.asmx",
"WebServiceWSDLMapping":
{
"Service.asmx":
{
"WsdlFile": "SOAP.wsdl",
"SchemaFolder": "D: /",
"WsdlFolder": "D: /"
}
}
},
"VirtualPath": "",
The problem is that when I try to run the application I get the following error:
An unhandled exception occurred while processing the request.
XmlException: Root element is missing.
System.Xml.XmlTextReaderImpl.Throw (Exception e)
Some help?
I'm using ASP.NET Core 3.1.
My Startup.cs
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.ServiceModel;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Models;
using SoapCore;
using Microsoft.Extensions.Configuration;
namespace SoapServer
{
public class Startup
{
private readonly IConfiguration Configuration;
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.TryAddSingleton<ISampleService, SampleService>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
var settings = Configuration.GetSection("FileWSDL").Get<WsdlFileOptions>();
settings.AppPath = env.ContentRootPath; // The hosting environment root path
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Hello World!");
});
});
app.UseSoapEndpoint<ISampleService>("/Service.asmx", new BasicHttpBinding(), SoapSerializer.XmlSerializer, false, null, settings);
}
}
}
All xml files (wsdl files are xml too) must have a root element: https://www.w3schools.com/xml/xml_syntax.asp
Valid Example:
InValid Example:
So it's either that your wsdl is invalid or that the application can't access it and you are using an empty file.