Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to get OWIN to host a SOAP service?

Tags:

rest

c#

soap

wcf

owin

How do I get OWIN to host a SOAP endpoint (do not care if WCF is or isn't involved, SOAP gives WSDL which makes services easier to consume by certain clients, that's why I want SOAP and REST)

I suspect the answer is: Implement your own middleware that hosts a SOAP endpoint. If that's the answer so be it, but that's a lot of work so I'll probably just end up sticking with WCF and avoiding OWIN if that's the case. I find it hard to believe no one has implemented a SOAP hosting middleware yet...


As a rule we like to do both REST and SOAP endpoints on our services; currently we use IIS and the WCF restful bits to host the SOAP with [ServiceContract]/[OperationContract] attributes, and the rest is defined with [WebInvoke] attributes, with these attributes the services need no reimplementation for the different endpoint types.

We just use the ASP.NET routes to add new ServiceRoutes which add a rest binding to URI/REST with the same service as a soap binding to URI/SOAP.

Now we're looking at doing some new services work and I'd like to move forward to using OWIN so we can implement our new services with hosting agnosticism as some services will be better served by windows service hosting and some better served by IIS service hosting.

All of my fiddling with things and so far I can come up with no way of getting a SOAP endpoint hosted by OWIN. I have the rest handled fine by making my service inherit from ApiController and then using this little snippet of code in the OWIN app's Configuration method:

    public void Configuration(IAppBuilder app)
    {
        HttpConfiguration config = new HttpConfiguration();
        config.MapHttpAttributeRoutes();
        app.UseWebApi(config);
        [...]
like image 476
Jimmy Hoffa Avatar asked Oct 20 '22 12:10

Jimmy Hoffa


1 Answers

There is a custom OWIN middleware example on MSDN that shows how to support SOAP requests. It is not a general purpose WCF host but may be enough to expose your existing WCF Services (i.e. [ServiceContract/OperationContract]) within an ASP.NET Core app. The example does not include support for [WebGet/WebInvoke] but may be enough to get you started.

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

If your primary goal is simply to begin writing new services using OWIN and you still plan to host them in IIS using Microsoft.Owin.Host.SystemWeb. You could ignore the WCF requests within the OWIN pipeline and allow the IIS ASP.NET pipeline to handle them. This would enable you to write services that are a combination of OWIN middleware and traditional WCF endpoints.

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);
    }
}

Then call the IgnoreWCFRequests extension method when configuring your app.

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");
            });
    }
}
like image 131
cpowers Avatar answered Oct 23 '22 03:10

cpowers