Share via

Soap core - support for soap service response body manipulation in dotnet core

Anonymous
2025-03-12T10:27:18+00:00

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.

Microsoft 365 and Office | Install, redeem, activate | Other | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2025-03-18T06:32:24+00:00

    Hi Allen,

    Thanks a lot for your details reply. I had raised this query using 'Ask a Question' option in 'Training | Microsoft Learn' . Please find the link for the same as below.

    https://learn.microsoft.com/en-us/answers/questions/2236081/http-response-body-content-needs-to-be-set-from-so

    Your help or reply is much appreciated. Thanks in advance.

    0 comments No comments
  2. Anonymous
    2025-03-13T03:09:16+00:00

    Hi, Bhuvaneswari Vinayagamoorthi

    I noticed that your question relates to software development,I wish I could handle your problem, however, the issues seems to require more specialized support, I suggest you try to seek help at Microsoft Learn, where there are more experts in related fields who can provide you with better solutions.

    you can click on "Ask a question", there are experts who can provide more professional solutions in that place.

    Here is a link to the forum where you can raise specific scenarios and share your idea to help solve the problem.

    Training | Microsoft Learn

    Sincerely hope that your question will be dealt with appropriately after contact the correct department. Thank you for your understanding!

    Feel free to post back if you need further assistance. 

    Thank you for your understanding and patience and I look forward to hearing from you.

    Allen - MSFT | Microsoft Community Support Specialist

    0 comments No comments