我正在使用 SoapCore(用于 ASP.NET Core 的 SOAP 协议中间件)在我的本地计算机上使用现有的肥皂文件 (.WSDL) 创建一个 Soap 服务器。
我正在使用以下配置appsettings.json
:
"FileWSDL":
{
"UrlOverride": "/Service.asmx",
"WebServiceWSDLMapping":
{
"Service.asmx":
{
"WsdlFile": "SOAP.wsdl",
"SchemaFolder": "D: /",
"WsdlFolder": "D: /"
}
}
},
"VirtualPath": "",
问题是,当我尝试运行应用程序时,出现以下错误:
处理请求时发生未处理的异常。
XmlException:缺少根元素。
System.Xml.XmlTextReaderImpl.Throw(异常 e)
一些帮助?
我正在使用 ASP.NET Core 3.1。
我的启动.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);
}
}
}