locked
WCF service and client returning invalid response type RRS feed

  • Question

  • 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.

    Server config
    -------------

        <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>


    Client config
    -------------

        <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>

    Server method that is called
    ----------------------------

        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;
                            }

    MVC Controller code
    -------------------

        [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 call from the client to the service.
    -----------------------------------------

        $.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) {

     


    Bill Yeager

    Wednesday, December 3, 2014 2:54 AM

Answers

All replies

  • You are using the ajax to call the service with Post method. But your service is a wcf soap service which do not support the post method. Try use the webhttpbinding instead of the basichttpbinding.
    Thursday, December 4, 2014 6:29 AM
  • wcf does support soap. It wad a load balancer issue...

    Bill Yeager

    Friday, December 5, 2014 8:00 PM
  • So you have solved your problem?
    Wednesday, December 10, 2014 6:42 AM
  • yes...

    Bill Yeager

    Wednesday, December 10, 2014 5:18 PM