Currently I have only worked with REST and setting my endpoints directly in the Controller.
For example:
[HttpGet("someEndpoint")]
Now I have to work with SOAP and I'm trying to set the endpoint in my Program.cs
(see screenshot). I'm always getting an error for the BasicHttpBinding()
.
My question: do I have to set the endpoints in the controller? The same way I'm doing it with my normal REST API? I didn't find an answer for this on the Internet. Thank you very much in advance.
(My native language is German, sorry for my English :) )
EDIT: the code:
using SoapCore;
using System.ServiceModel;
using WebAPI_2023.Models;
using WebAPI_2023.Services;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddSoapCore();
builder.Services.AddScoped<CalculatorService>();
builder.Services.AddSingleton<ISampleService, SampleService>();
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
app.UseSoapEndpoint<ISampleService>("/Service.asmx", new
BasicHttpBinding(), SoapSerializer.XmlSerializer);
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
EDIT 2 : I found my error.Now it works perfectly :)
app.UseEndpoints(endpoints =>
{
endpoints.UseSoapEndpoint<ISampleService>("/Service.asmx", new
SoapEncoderOptions(), SoapSerializer.XmlSerializer);
});
CodePudding user response:
Do I have to set the Endpoints in the Controller? The same way im doing it with my normal REST API´s? I didnt find an answer for this on the Internet
Well, for Web Service
integration within the asp.net core project
regardless of version there are two
Step:2
Step:3
Implementation Using asmx URL:
Note: If your Web Service
up and running it will start adding the reference without any issue.
Implementation Using WSDL file:
Note: You should select path
for your valid wsdl file
here. Ignore my files here, you outght to choose your wsdl file
instead.
Use Your Service Inside Your Web API/MVC Controller
Now, In your Web API project, you could use a service reference added earlier. Like below
Please note that, you should call the method according to the WCF service's method.
var serviceReference1 = new ServiceReference1.Service1Client();
var result = await serviceReference1.GetDataAsync(1) ;
If you still encounter any further issue for integration you could refer to our official document for more details here