Reputation: 4692
I've read every pertinent question on the web regarding this exact error:
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)
However, I still can't determine what the actual cause of the error is. It happens randomly with 4 web servers behind a load balancer. When the error occurs, I manually type in one of the webserver names in the address bar where the load balancer name is. The data won't be retrieved from one of the web servers for that particular instance, but if I try on of the other servers, I'll get the data back.
We can't expect our users to manually change the url of the load balancer to one of the 4 server names to try and get a hit.
From what I read, it seems like a config error between the client and server. If that was the case, wouldn't it be happening all the time? The error is obviously happening on the client side inside the MVC controller method from my logging messages.
I'm posting my code down below and hope that somebody can answer this question. I would really appreciate it.
<system.serviceModel>
<services>
<service name="FuelTktImgRetrievalSvc.FuelTktImgRetrieval" behaviorConfiguration="ServiceBehavior">
<endpoint address="" binding="basicHttpBinding" contract="FuelTktImgRetrievalSvc.IFuelTktImgRetrieval" bindingConfiguration="BasicHttpBinding_IFuelTktImgRetrieval">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<!--<add baseAddress="\\miavdeteoabweb\applications\FuelTktImgRetrievalSvc" />-->
</baseAddresses>
</host>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IFuelTktImgRetrieval" closeTimeout="00:10:00"
openTimeout="00:10:00" receiveTimeout="04:00:00"
sendTimeout="04:00:00" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" />
</basicHttpBinding>
</bindings>
<diagnostics wmiProviderEnabled="false" performanceCounters="All">
<messageLogging logMessagesAtTransportLevel="true" logMessagesAtServiceLevel="true" logMalformedMessages="true" logEntireMessage="true" maxSizeOfMessageToLog="2147483647" maxMessagesToLog="500" />
</diagnostics>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IFuelTktImgRetrieval" />
</basicHttpBinding>
</bindings>
<diagnostics wmiProviderEnabled="true">
<messageLogging logMessagesAtTransportLevel="true" logMessagesAtServiceLevel="true" logMalformedMessages="true" logEntireMessage="true" maxSizeOfMessageToLog="2147483647" maxMessagesToLog="500" />
</diagnostics>
<client>
<endpoint address="http://ride/FuelTktImgRetrievalSvc/FuelTktImgRetrieval.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IFuelTktImgRetrieval"
contract="FuelTktImgRetrievalSvc.IFuelTktImgRetrieval" name="BasicHttpBinding_IFuelTktImgRetrieval" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="webhttp">
<webHttp />
</behavior>
<behavior name="BasicHttpBinding_IFuelTktImgRetrieval">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
public async Task<List<HH_FuelTkt_Output>> GetFilteredFuelTicketsAsync(HH_FuelTkt_Input value)
{
using (HandheldEntities DbContext = new HandheldEntities())
{
using (var dbcxtTrans = DbContext.Database.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted))
{
try
{
// code left out for brevity
List<HH_FuelTkt_Output> tkts_Combined = await tkts.ToListAsync();
dbcxtTrans.Commit();
return tkts_Combined;
}
[HttpPost]
public async Task<JsonResult> GetFilteredFuelTicketsAsync(HH_FuelTkt_Input id)
{
try
{
IEnumerable<HH_FuelTkt_Output> fto = await db.GetFilteredFuelTicketsAsync(id);
return Json(fto, JsonRequestBehavior.AllowGet);
}
$.ajax({
url: '@Url.Action("GetFilteredFuelTicketsAsync", "Home")',
data: JSON.stringify(HH_FuelTkt_Input),
dataType: 'json',
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
Upvotes: 1
Views: 1069
Reputation: 3665
This is presumably an error you see on the client rather than the server. The error message states that it received text/html
when it was expecting text/xml
. This is usually the case when the service is being hosted in IIS and some issue with the server causes it to respond with an ASP.NET error page (which will be HTML) rather than a SOAP response (which would be XML). The intermittent nature of the error and the fact your are using a load-balancer suggests to me that one of the servers behind the load balancer has something wrong with it.
Can you reach the servers individually? Try browsing to the .svc page for each server and/or invoking the web service in a tool like soapui and you should see the HTML error page. Alternatively try trawling the Windows Event Log for ASP.NET errors on each server and you may find one of the old errors logged.
Upvotes: 1