Mel*_*per 2 c# soap web-services asp.net-core
在经典的ASP.NET中,我们将简单地用WebMethod属性标记一个方法以创建可以从外部应用程序调用的SOAP服务方法。我们如何使用ASP.NET Core达到相同的目的?
它必须基于XML SOAP。它必须与在ASP.NET类为后端时工作的客户端兼容。
您可以使用SOAPCore NuGet包来实现这一点。假设您有一个如下合同:
[ServiceContract]
public interface IPingService
{
[OperationContract]
string Ping(string msg);
}
Run Code Online (Sandbox Code Playgroud)
并执行:
public class SampleService : IPingService
{
public string Ping(string msg)
{
return string.Join(string.Empty, msg.Reverse());
}
}
Run Code Online (Sandbox Code Playgroud)
然后注册服务:
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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3305 次 |
| 最近记录: |