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.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With