gpt4 book ai didi

c# - 多个中间件(REST + SOAP)

转载 作者:行者123 更新时间:2023-12-02 18:36:40 25 4
gpt4 key购买 nike

我已按照本教程进行操作:custom-asp-net-core-middleware-example

现在我想添加一个默认的 REST 中间件,它处理所有包含 JSON 内容的请求,但当我不注册自己的中间件时,找不到哪个是来自 ASP.NET 的 REST 中间件。

有人可以告诉我如何使用多个中间件,其中一个是 SOAP,另一个是 REST 中间件?

这是我注册中间件的代码:

public static class SOAPEndpointExtensions
{
public static IApplicationBuilder UseSOAPEndpoint(this IApplicationBuilder builder)
{
return builder.UseMiddleware<SOAPEndpointMiddleware>();
}

public static IApplicationBuilder UseSOAPEndpoint<T>(this IApplicationBuilder builder, string path, MessageEncoder encoder)
{
return builder.UseMiddleware<SOAPEndpointMiddleware>(typeof(T), path, encoder);
}

public static IApplicationBuilder UseSOAPEndpoint<T>(this IApplicationBuilder builder, string path, Binding binding)
{
var encoder = binding.CreateBindingElements().Find<MessageEncodingBindingElement>()?.CreateMessageEncoderFactory().Encoder;
return builder.UseMiddleware<SOAPEndpointMiddleware>(typeof(T), path, encoder);
}
}

SOAPEndpointMiddleware.cs 与本教程中的内容基本相同。

最佳答案

添加 REST + SOAP:

public void ConfigureServices(IServiceCollection services)
{
services.AddControllers(); // REST API

// ....
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseSOAPEndpoint<YourService>("/YourService.svc", new BasicHttpBinding());

app.UseRouting();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers(); // REST API
});
}

关于c# - 多个中间件(REST + SOAP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68678573/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com