SoapCore: The envelope version of the incoming message (Soap12 (http://www.w3.org/2003/05/soap-envelope)) does not match that of the encoder (Soap11 (http://schemas.xmlsoap.org/soap/envelope/))

Hi All,

Thanks for your efforts in putting this together. Trying it on a sample project have have run into the above error message. From my searching it appears that “BasicHttpBinding” is related to Soap 1.1 and wsBasicHttpBinding is for SOAP 1.2. By the looks of it, using System.ServiceModel does not support the ws binding.

The error happens at: var requestMessage = _messageEncoder.ReadMessage(httpContext.Request.Body, 0x10000, httpContext.Request.ContentType); in SoapEndpointMiddleware.cs

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 17 (6 by maintainers)

Most upvoted comments

To Add some color into this issue as I’ve seen that it doesn’t seem to support custom binding. Code Example: // create Soap 1.2 Binding TextMessageEncodingBindingElement textBindingElement = new TextMessageEncodingBindingElement(MessageVersion.Soap12WSAddressing10, System.Text.Encoding.UTF8); HttpTransportBindingElement httpBindingElement = new HttpTransportBindingElement(); httpBindingElement.AllowCookies = true; httpBindingElement.MaxBufferSize = int.MaxValue; httpBindingElement.MaxReceivedMessageSize = int.MaxValue; CustomBinding soap12Binding = new CustomBinding(textBindingElement, httpBindingElement); // service app.UseSoapEndpoint<SoapService>(“/SoapService.svc”, soap12Binding);

Now call that service from a client and the stack trace is… Microsoft.AspNetCore.Server.Kestrel[13] Connection id “0HLBJT99U8TBU”, Request id “0HLBJT99U8TBU:00000001”: An unhandled exception was thrown by the application. System.InvalidOperationException: This message cannot support the operation because it has been read. at System.ServiceModel.Channels.Message.EnsureReadMessageState() at System.ServiceModel.Channels.Message.GetReaderAtBodyContents() at SoapCore.SoapEndpointMiddleware.GetRequestArguments(Message requestMessage, OperationDescription operation, Dictionary`2& outArgs) at SoapCore.SoapEndpointMiddleware.<ProcessOperation>d__7.MoveNext() — End of stack trace from previous location where exception was thrown —

I solved it with the following statement in the startup.cs:

TextMessageEncodingBindingElement textBindingElement = new TextMessageEncodingBindingElement(MessageVersion.Soap12WSAddressingAugust2004, System.Text.Encoding.UTF8);
HttpTransportBindingElement httpBindingElement = new HttpTransportBindingElement();
CustomBinding soap12Binding = new CustomBinding(textBindingElement, httpBindingElement);

app.UseSoapEndpoint<INotificationService>("/MyService.asmx", soap12Binding, SoapSerializer.XmlSerializer);

I implemented this kind of binding and now I am getting a different error.

crit: SoapCore.SoapEndpointMiddleware[0] An error occurred when trying to service a request on SOAP endpoint: /myendpoint.asmx System.InvalidOperationException: The body of the message cannot be read because it is empty. at System.ServiceModel.Channels.Message.GetReaderAtBodyContents() at SoapCore.SoapEndpointMiddleware.ProcessOperation(HttpContext httpContext, IServiceProvider serviceProvider) at SoapCore.SoapEndpointMiddleware.Invoke(HttpContext httpContext, IServiceProvider serviceProvider)

I solved it with the following statement in the startup.cs:

TextMessageEncodingBindingElement textBindingElement = new TextMessageEncodingBindingElement(MessageVersion.Soap12WSAddressingAugust2004, System.Text.Encoding.UTF8);
HttpTransportBindingElement httpBindingElement = new HttpTransportBindingElement();
CustomBinding soap12Binding = new CustomBinding(textBindingElement, httpBindingElement);

app.UseSoapEndpoint<INotificationService>("/MyService.asmx", soap12Binding, SoapSerializer.XmlSerializer);