System.Aggregateexception C# How to resolve?

Asked

Viewed 126 times

0

I’m trying to make a connection with a webservices but I’m having the following error:

System.AggregateException: 'One or more errors occurred. (Message part {http://cliente.bean.master.sigep.bsb.correios.com.br/}consultaSRO was not recognized.  (Does it exist in service WSDL?))'
FaultException: Message part {http://cliente.bean.master.sigep.bsb.correios.com.br/}consultaSRO was not recognized.  (Does it exist in service WSDL?)

How to solve this problem?

Follow my Controller on C#

// POST api/values
[EnableCors("*","*","*")]
[HttpPost]
public JObject Post([FromBody] Rastreamento model) 
{
    // Aciona o webservice para busca dos dados
    var client = new ServiceReference.AtendeClienteClient();
    string[] lista = { model.Objetos};

    Task<ServiceReference.consultaSROResponse> xml = client.consultaSROAsync(lista, model.Tipo, model.Resultado, model.Usuario, model.Senha);

    // xml.Wait();


    XmlDocument doc = new XmlDocument();
    //transforma o documento XML em uma string  e o lê
    doc.LoadXml(xml.Result.@return);

    var stringJson = JsonConvert.SerializeXmlNode(doc, Newtonsoft.Json.Formatting.None, false);
    // converte a string em um documento JSON
    JObject json = JsonConvert.DeserializeObject<JObject>(stringJson);

    return json;
} 

Method Consultasrorespo

public partial class consultaSROResponse
{

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://cliente.bean.master.sigep.bsb.correios.com.br/", Order=0)]
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string @return;

    public consultaSROResponse()
    {
    }

    public consultaSROResponse(string @return)
    {
        this.@return = @return;
    }
}
  • If I’m not mistaken this error means that the path you are making the request does not exist. Check the request address

  • 1

    Update the Webservice reference.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.