The content type text/xml; charset="utf-8" of the response message does not match the content type of the binding (text/xml; charset=utf-8)
It would indeed seem that the .NET Core version is more picky about this. In any case, I managed to solve it using a Custom Encoder.
I blatently stole the CustomTextMessageEncoder from Github. I added the following method:
public override bool IsContentTypeSupported(string contentType)
{
return true;
}
And stole CustomTextMessageBindingElement
and CustomTextMessageEncoderFactory
from the same place.
I added them by creating a custom binding (basicBinding is the binding I had before):
var customBindingElement = new CustomTextMessageBindingElement("UTF-8", "text/xml", MessageVersion.Soap11);
var binding = new CustomBinding(basicBinding);
binding.Elements.RemoveAt(0);
binding.Elements.Insert(0, customBindingElement);
var client = (T2)Activator.CreateInstance(typeof(T), binding, address);
I use Activator as I generate my proxies dynamically. Just replace with a call to the WCF generated client.
Quite a lot of work for two misplaced quotes :D
![Troels Larsen](https://i.stack.imgur.com/TDlpy.jpg?s=256&g=1)
Troels Larsen
By day, I fix NotImplementedExceptions, mostly in C#, but also in Javascript, Python or whatever comes my way. By night, I dabble in building a home automation system using various bits and pieces like Arduino, ESP8266, Raspberry Pi. I'm having fun with Docker, NET Core, Node.JS for the server side of things. And Angular2 for the web.
Updated on July 01, 2022Comments
-
Troels Larsen almost 2 years
Please note that this question pertains to the .NET Core implementation of WCF Connected Services.
I am porting a regular .NET WCF client over to .NET Core, but I ran into this issue:
The content type text/xml; charset="utf-8" of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '<?xml version='1.0' encoding='UTF-8'?> [...]
The response indeed contains the quotes:
HTTP/1.1 200 Ok content-type: text/xml; charset="utf-8"
I never did anything special to handle this in WCF proper. Is this a bug in the .NET Core version, or is it just really specific about the content type (utf-8 vs "utf-8")?
How can I change the expected content type to match the service I'm calling? (I have no control over that, but I can copy and alter the WSDL if needed).
I'm using a svcutil-generated client. (Connected Service)
-
crackedcornjimmy about 7 yearsCan you point me to an example of where to add this to my .Net Core project? I'm having the same issue.
-
Troels Larsen about 7 yearsI tried to update my answer to show how I use the 'stolen' classes.
-
crackedcornjimmy about 7 yearsOMG!!!!!!!!!!!!! That actually works! I was missing the step of...well...all the steps. You're a genius. Thank you so much!
-
Troels Larsen about 7 years@crackedcornjimmy: I can relate. Fixing those two stupid quotes took WAAY longer than I had hoped. Glad I could help.
-
Rodrigo Leite about 6 yearsI was trying to solve this error for days... that help me a lot. thank you!
-
shobhonk about 6 yearsHas his been raised as a bug in git hub for this project? or is it even a bug. a lot of old web services break if custom encoder is not implemented
-
Troels Larsen about 6 years@shobhonk: Personally, I haven't. It seemed like an incorrect implementation in the service I was calling, but I may be wrong.
-
Ted almost 4 yearsFor fellow WCF noddies running into this problem and solution, Troels' code has to be placed into the GetBindingForEndpoint() method of your generated
Reference.cs
file, and in my case (and probably yours) without the Activator line. Good work Troels!