WcfCoreMtomEncoder icon indicating copy to clipboard operation
WcfCoreMtomEncoder copied to clipboard

Wrong part is used as mainPart and therefore breaks on GetRawContent

Open michel-jump opened this issue 3 years ago • 0 comments

Hi, thanks for making it possible to support MTOM for dotnet 5.

I am experiencing the following Exception:

System.ArgumentNullException: Value cannot be null. (Parameter 'input')
   at System.Text.RegularExpressions.ThrowHelper.ThrowArgumentNullException(ExceptionArgument arg)
   at System.Text.RegularExpressions.Regex.IsMatch(String input)
   at System.Text.RegularExpressions.Regex.IsMatch(String input, String pattern, RegexOptions options)
   at WcfCoreMtomEncoder.MtomPart.GetRawContent()
   at WcfCoreMtomEncoder.MtomPart.GetStringContentForEncoder(MessageEncoder encoder)
   at WcfCoreMtomEncoder.MtomMessageEncoder.ReadMessage(Stream stream, Int32 maxSizeOfHeaders, String contentType)
   at WcfCoreMtomEncoder.MtomMessageEncoder.ReadMessage(ArraySegment`1 buffer, BufferManager bufferManager, String contentType)
   at System.ServiceModel.Channels.MessageEncoder.ReadMessageAsync(Stream stream, BufferManager bufferManager, Int32 maxBufferSize, String contentType, CancellationToken cancellationToken)
   at System.ServiceModel.Channels.HttpResponseMessageHelper.ReadChunkedBufferedMessageAsync(Task`1 inputStreamTask, TimeoutHelper timeoutHelper)
   at System.ServiceModel.Channels.HttpResponseMessageHelper.ParseIncomingResponse(TimeoutHelper timeoutHelper)
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpClientRequestChannel.HttpClientChannelAsyncRequest.ReceiveReplyAsync(TimeoutHelper timeoutHelper)
   at System.ServiceModel.Channels.RequestChannel.RequestAsync(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.RequestAsyncInternal(Message message, TimeSpan timeout)
   at System.Runtime.TaskHelpers.WaitForCompletionNoSpin[TResult](Task`1 task)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(MethodCall methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(MethodInfo targetMethod, Object[] args)

While debugging this package I observed the following: MtomMessageEncoder.ReadMessage tries to get the mainPart by searching for the part with the parameter 'start'. If this parameter is not present, then it will take the first part.

With this mainPart, it will try to get the string content of that part. Before trying it will check if the Content-Transfer-Encoding is set to binary.

My issue is that the first part in the response I get from the WCF service is not a binary, but an XML. This part therefore has no Content-Transfer-Encoding. image

Do you know how to mitigate this problem?

michel-jump avatar Jul 14 '21 14:07 michel-jump