Error in consuming web service c # [duplicated]


Good morning, when I consume a public web service in C# I get this message. What can be due?

The content type text/html of the response message does not match the content type of the text/xml; charset=utf-8 link. If you use a custom encoder, make sure that the IsContentTypeSupported method is implemented correctly.

The first 1024 bytes of the response were:

<html lang="es-ES">
   <title>Agencia Tributaria - Se ha producido un error</title>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">       
<link href="" orel="stylesheet" type="text/css">
<script type="text/javascript"> 
function toggle()
   var o=document.getElementById("AEAT_errores_tecnicos");'' || .style.display=='none')?'block':'none';

This is my code, can it be that the certificate is not well added?

 X509Store store = new X509Store(StoreName.My,

    LRConsultaEmitidasType ddd = new LRConsultaEmitidasType();
    SuministroLRFacturasEmitidas iverview = new   SuministroLRFacturasEmitidas();
    // sca.ClientCertificates.Add(store.Certificates[3]);

    sca.ClientCredentials.ServiceCertificate.SetDefaultCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindBySerialNumber, "1234567890");


    catch (Exception ex)

asked by Carlos Calvo 06.02.2017 в 15:19

1 answer


The problem is that the service you are invoking is generating an internal error returning the html from the error page

  • If the service you invoke is your own, you could put a breakpoint and evaluate what is the error that is being generated.

  • If it is an error in production, you could define in the code a block % try...catch covering the whole service, in this way when
    fail you can capture it and return the exception message as xml so that it does not affect the form expected by the client and you can | process the error message. Even better if you can on the server log the problem to have a greater detail of the problem.

It is clear that the problem is an uncontrolled error within the service, then returns the default page with the description of the problem. Your client is not prepared to receive this html and process it, since he only understands the xml with the response data

answered by 06.02.2017 в 19:34