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)

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

WCF charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8)

As I suspected - your client-side config looks like this:

  <endpoint name="WSHttpBinding_ICommAccountingBinding" 
address="https://secure.inmatecanteen.com/CommAccountingService/CommAccountingWeb.svc"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IInmateCanteenServiceWeb"
contract="CommAccountingWeb.ICommAccountingWeb" />

It expects wsHttpBinding - but the server-side address it's connecting to is:

 <service name="CommAccountingWeb.CommAccountingWeb"  
behaviorConfiguration="HttpMexBehavior">
<endpoint
address=""
behaviorConfiguration="httpBehavior"
binding="webHttpBinding" bindingConfiguration="myWebHttpBinding"
contract="CommAccountingWeb.ICommAccountingWeb" />
<host>
<baseAddresses>
<add baseAddress="https://secure.inmatecanteen.com/CommAccountingService/CommAccountingWeb.svc"></add>
</baseAddresses>
</host>
</service>

and this server endpoint uses webHttpBinding.

So while the client expects a SOAP XML message (content type: application/soap+xml; charset=utf-8), the server-side endpoint is a REST endpoint which returns plain XML (content type: application/xml; charset=utf-8)

Solution: you need to make sure both the client and the server endpoint used are in sync with regards to bindings and configuration!

The content type application/xml;charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8)

It's possible that your WCF service is returning HTML. In this case, you'll want to set up a binding on the service side to return XML instead. However, this is unlikely: if it is the case, let me know and I'll make an edit with more details.

The more likely reason is that your service is throwing an error, which is returning an HTML error page. You can take a look at this blog post if you want details.

tl;dr:
There are a few possible configurations for error pages. If you're hosting on IIS, you'll want to remove the <httpErrors> section from the WCF service's web.config file. If not, please provide details of your service hosting scenario and I can come up with an edit to match them.

EDIT:

Having seen your edit, you can see the full error being returned. Apache can't tell which service you want to call, and is throwing an error for that reason. The service will work fine once you have the correct endpoint - you're pointed at the wrong location. I unfortunately can't tell from the information available what the right location is, but either your action (currently null!) or the URL is incorrect.

The content type text/html; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8)

Since the returned content type is text/html, I suspect your call result in a server-side error outside of WCF (you are receiving an HTML error page).

Try viewing the response with a web debugging proxy such as Fiddler.


(Edit based on comments) :

Based on your comments, I see that your WCF is hosted under Sharepoint 2010, in a form-authenticated site.

The error you are receiving is due to the fact that your your WCF client is NOT authenticated with sharepoint -- it does not have a valid authentication cookie. Sharepoint then return an HTTP Redirect to an html page (the login.aspx page); which is not expected by your WCF client.

To go further you will have to obtain an authentication cookie from Sharepoint (see Authentication Web Service) and pass it to your WCF client.


(Updated edit) :

Mistake: The site is using claim based authentication.

Although this is not necessarily due to cookies or form authentication, the explaination of the provided error message remain the same. An authentication problem cause a redirection to an HTML page, which is not handled by the WCF client.

WCF Service Client: The content type text/html; charset=utf-8 of the response message does not match the content type of the binding

Try browsing to http://localhost/ScraperService.svc in the web browser on the server hosting the service, using the same Windows credentials that the client normally runs under.

I imagine that IIS is displaying an html error message of some description instead of returning xml as expected.

This also can occur when you have an http proxy server that performs internet filtering. My experience with ContentKeeper is that it intercepts any http/https traffic and blocks it as "Unmanaged Content" - all we get back is an html error message. To avoid this, you can add proxy server exception rules to Internet Explorer so that the proxy doesn't intercept traffic to your site:

Control Panel > Internet Options > Connections > LAN Settings > Advanced > Proxy Settings

enter image description here



Related Topics



Leave a reply



Submit