Hi Team,
My application was developed as soap service(asmx) in dotnet framework. In that response was set in its body with 'CurrentContext.Current.Response.WriteAsync("required content")' implementation.
Recently we migrated our soap service from dotnet framework to Dotnet core(8.0). Here we used 'SoapCOre' nuget package to expose our service as soap from dot net core solution as shown below.
services.AddSingleton();
app.UseSoapEndpoint(path: "/ourService.asmx", new SoapEncoderOptions(), SoapSerializer.XmlSerializer, true, null,null, true, true);
Now we are facing issue with http response. when we run the application , all the functionality is working fine, but once the response is set(CurrentContext.Current.Response.WriteAsync("required content")) in our webmethod , from the pipeline below exception got logged in the event viewer. If we remove the response.WriteAsync() method then this error is not occuring. But in our application we have to set the required content in the response body only. Kindly help to resolve the same.
Your help will be appreciated. thanks in advance.
Category: Microsoft.AspNetCore.Server.Kestrel
EventId: 13
SpanId: 68ba32138464e12e
TraceId: 859e4a456624db74758ca1d235ae8f12
ParentId: 0000000000000000
ConnectionId: 0HNAQSQS4HJUO
RequestId: 0HNAQSQS4HJUO:00000002
RequestPath: /ourservice.asmx/ourMethod
Connection id "0HNAQSQS4HJUO", Request id "0HNAQSQS4HJUO:00000002": An unhandled exception was thrown by the application.
Exception:
System.InvalidOperationException: StatusCode cannot be set because the response has already started.
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ThrowResponseAlreadyStartedException(String value)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.set_StatusCode(Int32 value)
at SoapCore.SoapEndpointMiddleware`1.ProcessHttpOperation(HttpContext context, IServiceProvider serviceProvider, String methodName) in /_/src/SoapCore/SoapEndpointMiddleware.cs:line 423
at SoapCore.SoapEndpointMiddleware`1.Invoke(HttpContext httpContext, IServiceProvider serviceProvider) in /_/src/SoapCore/SoapEndpointMiddleware.cs:line 155
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
at Microsoft.WebTools.BrowserLink.Net.BrowserLinkMiddleware.InvokeAsync(HttpContext context)
at Microsoft.AspNetCore.Watch.BrowserRefresh.BrowserRefreshMiddleware.InvokeAsync(HttpContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequestsTContext
Regards,
Bhuvana.