API request mails returning null

Asked

Viewed 2,531 times

4

I have a problem with my code c#, I am trying to consume the Post Office API but the data is null. I found another tutorial on the internet that said to instantiate the class trace and grab the property rastroJSON but my service does not own this property(rastroJSON), being that property rastroJSON displayed on page 7 of the Post Office documentation.

My attempt coming in the null data:

correios.rastro a = new correios.rastro();
correios.sroxml xml = new correios.sroxml();
xml = a.buscaEventos("ECT", "SRO", "", "U", "", "CODIGO");
Console.WriteLine(xml.objeto);
Console.ReadKey();

correios is the namespace of my reference.

The object of consolewriteline come null, I created a service reference with the address: http://webservice.correios.com.br/service/rastro/Rastro.wsdl

I tried to follow the manual, but it didn’t work.

I created first with a service reference, soon after I tried creating a web service reference, in the advanced properties.

  • The User, Password I assume you have, right? Test with the call below by placing the data in the URL: As I have no user and password here to test for me returns null too. http://webservice.correios.com.br/service/rastro/Rastro.wsdl?%22usuario=9999999999&password=S@1234YWC5&type=L&result=T&lingua=101&objects=JO999999999BR

  • I’m in this trouble too, you managed to fix it?

2 answers

1

Your code is correct.

    correios.rastro a = new correios.rastro();
    correios.sroxml xml = new correios.sroxml();
    xml = a.buscaEventos("usuario", "senha", "tipo", "resultado", "lingua", "objetos");
    Console.WriteLine(xml.objeto);
    Console.ReadKey();

For the searchThanks you have these parameters:

user

Informed by the area post office in activation of the service. This field differentiates letters upper and lower case (case-sensitive).

password

Informed by the area post office in activation of the service. This field differentiates letters capital letters and min

guy

L: list of objects. O server will make the query individual of each informed identifier; F: range of objects. The server will make the query sequential from first to last informed object,

outworking

W: all will be returned the events of the object; U: will be returned only the last event of the object.

tongue

101: Will be returned all events on languageen 102: Will be returned all events on english language.

objects

Code of the formed object by 2 letters, 9 numbers and 2 letters. This field differentiates capital letters and lower case (casesensitive). Example: AA458226057BR (always report everything in capital letters).

Example: http://webservice.correios.com.br/service/rastro/Rastro.wsdl?"usuario=9999999999&password=S@1234YWC5&tipo=L&resultado=T&lingua=101&objetos=JO999999999999BR

0

I was able to identify the problem. By importing the WSDL reference to class sroxml with explicit properties, one of them is the one that is returning null object.

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("objeto", Order=4)]
        public objeto[] objeto {
            get {
                return this.objetoField;
            }
            set {
                this.objetoField = value;
                this.RaisePropertyChanged("objeto");
            }
        }

Just change the value of the first Xmlelementattribute parameter to Form=System.xml.Schema.XmlSchemaForm.Unqualified:

[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=4)]

Try to run the Webservice call again and you will have typed the answer.

I do not know why wsdl is configured to generate the class in this way, only know that only by changing this the Webservice started to bring the complete object.

There are other fields with this same problem, just repeat the solution.

Browser other questions tagged

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