c# - 有什么方法可以让 OWIN 托管 SOAP 服务?

标签 c# wcf rest soap owin

如何让 OWIN 托管 SOAP 端点(不要关心是否涉及 WCF,SOAP 提供 WSDL,这使得某些客户端更容易使用服务,这就是我想要 SOAP 和 REST 的原因)

我怀疑答案是:实现您自己的托管 SOAP 端点的中间件。如果那是答案,那就这样吧,但这需要大量工作,所以如果是这种情况,我可能最终会坚持使用 WCF 并避免使用 OWIN。我很难相信还没有人实现过 SOAP 托管中间件...


通常我们喜欢在我们的服务上同时使用 REST 和 SOAP 端点;目前我们使用 IIS 和 WCF restful bits 来托管带有 [ServiceContract]/[OperationContract] 属性的 SOAP,其余部分由 [WebInvoke]< 定义 属性,有了这些属性,服务就不需要为不同的端点类型重新实现。

我们只是使用 ASP.NET 路由来添加新的 ServiceRoute,它使用与 soap 绑定(bind)到 URI/SOAP 相同的服务来添加到 URI/REST 的 rest 绑定(bind)。​​

现在我们正在考虑做一些新的服务工作,我想继续使用 OWIN,这样我们就可以在托管不可知论的情况下实现我们的新服务,因为一些服务将通过 Windows 服务托管得到更好的服务,而另一些服务将得到更好的服务通过 IIS 服务托管。

我所有的摆弄,到目前为止,我无法想出获得 OWIN 托管的 SOAP 端点的方法。通过使我的服务继承自 ApiController 然后在 OWIN 应用程序的 Configuration 方法中使用这一小段代码,我可以很好地处理其余部分:

    public void Configuration(IAppBuilder app)
    {
        HttpConfiguration config = new HttpConfiguration();
        config.MapHttpAttributeRoutes();
        app.UseWebApi(config);
        [...]

最佳答案

MSDN 上有一个自定义 OWIN 中间件示例,展示了如何支持 SOAP 请求。它不是通用 WCF 主机,但可能足以公开您现有的 WCF 服务(即 [ServiceContract/OperationContract]) 在 ASP.NET Core 应用程序中。该示例不包括对 [WebGet/WebInvoke] 的支持,但可能足以让您入门。

https://blogs.msdn.microsoft.com/dotnet/2016/09/19/custom-asp-net-core-middleware-example/

如果您的主要目标只是开始使用 OWIN 编写新服务,并且您仍计划使用 Microsoft.Owin.Host.SystemWeb 在 IIS 中托管它们 .您可以忽略 OWIN 管道中的 WCF 请求并允许 IIS ASP.NET 管道处理它们。这将使您能够编写结合了 OWIN 中间件和传统 WCF 端点的服务。

public static class WCFAppBuilderExtensions
{
    public static IAppBuilder IgnoreWCFRequests(this IAppBuilder builder)
    {
        return builder.MapWhen(context => IsWCFRequest(context), appBuilder =>
        {
            // Do nothing and allow the IIS ASP.NET pipeline to process the request
        });
    }

    private static bool IsWCFRequest(IOwinContext context)
    {
        // Determine whether the request is to a WCF endpoint
        return context.Request.Path.Value.EndsWith(".svc", StringComparison.OrdinalIgnoreCase);
    }
}

然后在配置您的应用时调用IgnoreWCFRequests 扩展方法。

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        var config = new HttpConfiguration();
        WebApiConfig.Register(config);
        app
            .IgnoreWCFRequests()
            .UseWebApi(config)
            .Run(context =>
            {
                return context.Response.WriteAsync("Default Response");
            });
    }
}

关于c# - 有什么方法可以让 OWIN 托管 SOAP 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22565488/

相关文章:

.net - WCF中的后台线程

c# - 使用linq使用另一个条件删除一个列表中的元素

c# - 我需要 "transactionScope.Complete();"吗?

c# - 为什么 AspNetCompatibilityRequirementsMode.Allowed 会修复此错误?

xml - 为什么 WCF 服务返回 xml 序列化对象?

java - android studio 中的 Android URLConnection.setRequestProperty() 似乎没有做任何事情

java - 为什么 jsonParser.getCodec().readTree(jsonParser).asText() 为我返回一个空字符串?

php - Laravel POST请求错误405 : MethodNotAllowedHttpException

javascript - 没有在另一个页面上获取 c# webmethod json 字符串

c# - 部署托管到 Azure 的 Blazor WebAssembly 应用程序 ASP.NET Core