WcfCoreMtomEncoder icon indicating copy to clipboard operation
WcfCoreMtomEncoder copied to clipboard

"utf-8" Quotation Marks at encoding leads to error // Fix Found?

Open M4nju opened this issue 4 years ago • 0 comments

The old Mtom Soap Service we need to use in our .net core project returns as Content-Type this value: Content-Type: application/xop+xml; type="application/soap+xml"; charset="utf-8"

Error Message: Encoding is not supported ""utf-8""

The quotation marks lead to an error while trying to find the correct charset encoding. At one place in this library the quotation marks are replaced, but this seems not to be enough. I made a small change inside the class "MtomPart" at the Property ContentType, which did the job:

 public MediaTypeHeaderValue ContentType
        {
            get
            {
                string contentTypeHeaderValue = _part.Headers.GetValues("Content-Type").FirstOrDefault();

                if (!String.IsNullOrEmpty(contentTypeHeaderValue) && MediaTypeHeaderValue.TryParse(contentTypeHeaderValue.TrimEnd(';'), out var parsedValue))
                {
                    parsedValue.CharSet= parsedValue.CharSet.Replace("\"", "");
                    parsedValue.MediaType= parsedValue.MediaType.Replace("\"", "");
                    return parsedValue;
                }

                return _part.Headers.ContentType;
            }
        }

Could you release a new nuget package version with this fix?

Any way thanks for the great work with the mtom implementation :D

Regards Manju

M4nju avatar May 26 '21 16:05 M4nju