Consuming a SOAP web service in controller
I added a service from a wsdl in the connected services through "Microsoft WCF Web Service Reference Provider"
It generated all the classes correctly. Now I want to consume this service when I access a api controller at a certain endpoint.
This is the interface of the service that will be called, it has an implementation as well called "SyncRequestPortChannel" which is too long to include here
[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "1.0.0.1")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://www.megatravel.xyz/XMLSchemaSoap", ConfigurationName="SyncReservations.SyncRequestPort")]
public interface SyncRequestPort
{
[System.ServiceModel.OperationContractAttribute(Action="", ReplyAction="*")]
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
System.Threading.Tasks.Task<SyncReservations.syncResponse1> syncAsync(SyncReservations.syncRequest1 request);
}
In Startup.cs I addded this
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
// Instanciranje servisa pri pokretanju aplikacije
services.TryAddSingleton<IHelloWorldService, HelloWorldService>();
//
services.AddScoped<SyncRequestPort, SyncRequestPortClient>();
}
And finally in my controller I referenced the SyncRequestPort interface hoping to get the implementation SyncRequestPortClient, however I got a NullReferenceException, the _client isn't instantiated
[Route("api/[controller]")]
[ApiController]
public class ReservationController : ControllerBase
{
private SyncRequestPort _client;
// GET: api/Reservation
[HttpGet]
public IEnumerable<SyncReservations.reservation> Get()
{
Task<syncResponse1> response = _client.syncAsync(new syncRequest1());
return response.Result.syncResponse.reservations;
}
What is the problem with this code? I have searched everywhere for a solution, please help
0 comments:
Post a Comment