You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ASP.NET Core 6中SOAP端点配置问题咨询

SOAP接口配置问题及解决记录

问题背景与疑问

之前只开发过REST接口,都是直接在Controller中通过特性配置端点,示例如下:

[HttpGet("someEndpoint")]

现在需要开发SOAP接口,尝试在Program.cs中配置端点,但调用BasicHttpBinding()时一直报错。想咨询:是否需要像配置REST API那样在Controller中设置SOAP端点?

(注:母语为德语,英文表述欠佳,请见谅)

附报错截图:
报错截图

初始配置代码

using SoapCore;
using System.ServiceModel;
using WebAPI_2023.Models;
using WebAPI_2023.Services;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddSoapCore();
builder.Services.AddScoped<CalculatorService>();
builder.Services.AddSingleton<ISampleService, SampleService>();
builder.Services.AddControllers();

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

app.UseSoapEndpoint<ISampleService>("/Service.asmx", new 
BasicHttpBinding(), SoapSerializer.XmlSerializer);

if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();

app.Run();

问题解决

已找到错误,现在运行正常,修改后的配置代码如下:

app.UseEndpoints(endpoints =>
{
    endpoints.UseSoapEndpoint<ISampleService>("/Service.asmx", new 
    SoapEncoderOptions(), SoapSerializer.XmlSerializer);
}); 

内容的提问来源于stack exchange,提问作者Timo Go

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 06:35:45