Error in consuming web service c # [duplicated]

1

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:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="es-ES">
<head>
   <title>Agencia Tributaria - Se ha producido un error</title>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">       
<link href="https://www.agenciatributaria.gob.es/static_files/common/css/xzhtcs04.css" orel="stylesheet" type="text/css">
<script type="text/javascript"> 
function toggle()
{
   var o=document.getElementById("AEAT_errores_tecnicos");
   o.style.display=(o.style.display=='' || .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,
  StoreLocation.CurrentUser);
    store.Open(OpenFlags.ReadOnly);

    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");

    //sca.(principal);
    try
    {
        sca.SuministroLRFacturasEmitidas(principal);

    }
    catch (Exception ex)
    { 

    }
    
asked by Carlos Calvo 06.02.2017 в 15:19
source

1 answer

3

The problem is that the service you are invoking is generating an internal error returning the html from the asp.net 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 asp.net 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