我正在使用SoapCore ( ASP.NET Core的Soap协议中间件)来使用本地机器上现有的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 Core3.1。
我的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);
}
}
}发布于 2021-02-06 11:04:42
所有xml文件(wsdl文件也是xml )必须有一个根元素:https://www.w3schools.com/xml/xml_syntax.asp
XML文档必须包含一个根元素,该根元素是所有其他元素的父元素。
有效的例子:
<root>
<child>
<subchild>.....</subchild>
</child>
<child>
<subchild>.....</subchild>
</child>
</root>InValid示例:
<child>
<subchild>.....</subchild>
</child>
<child>
<subchild>.....</subchild>
</child>所以,要么您的wsdl无效,要么应用程序无法访问它,而且您正在使用一个空文件。
发布于 2021-02-12 19:56:12
我也遇到了同样的问题,我的XML很好--只是找不到它。
我通过设置设置对象的AppPath值来解决这个问题:
var settings = Configuration.GetSection("FileWSDL").Get<WsdlFileOptions>();
settings.AppPath = AppDomain.CurrentDomain.BaseDirectory;
app.UseSoapEndpoint<Models.RateLinxWS>("/Shipping.asmx", new BasicHttpBinding() { Name = "RateLinxWSSoap", Namespace = "RateLinxWSSoap" }, SoapSerializer.XmlSerializer, false,null, settings);https://stackoverflow.com/questions/66075801
复制相似问题