Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serve SOAP from ASP.NET Core web method

In classic ASP.NET, we would simply mark a method with the WebMethod attribute to create a SOAP service method that could be called from an external app. How do we achieve the same with ASP.NET Core?

It must be XML SOAP based. It must be compatible with a client that worked when ASP.NET class was the back end.

like image 451
Christian Findlay Avatar asked Dec 19 '22 02:12

Christian Findlay


1 Answers

You can use the SOAPCore NuGet package to achieve that. Imagine you have a contract like below:

[ServiceContract]
public interface IPingService
{
    [OperationContract]
    string Ping(string msg);
}

And the implementation:

public class SampleService : IPingService
{
    public string Ping(string msg)
    {
        return string.Join(string.Empty, msg.Reverse());
    }
}

And then registration of the service:

public void ConfigureServices(IServiceCollection services)
{
     services.AddSingleton(new PingService());
     services.AddMvc();
     //rest goes here
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env,  ILoggerFactory loggerFactory)
{
    app.UseSoapEndpoint(path: "/PingService.svc", binding: new BasicHttpBinding());
    app.UseMvc();
    //rest goes here
}

Further Reading

  • How to Call WCF Services and Create SOAP Services with ASP.NET Core
  • Custom ASP.NET Core Middleware Example
like image 60
CodingYoshi Avatar answered Dec 28 '22 13:12

CodingYoshi