Bug record1: The underlying connection was closed: The connection was closed unexpectedly.Then

Description:

Setting up a c# console form for testing another web service called api.svc.

After running the web service and make sure it is running correctly, we create the service reference inside tester program.


It connect the two program successfully, but when do a request, at the receiving data point, keep on meeting this error:


The underlying connection was closed: The connection was closed unexpectedly.


First I thought it would be time out or receiving data too big. So I make following changes:

 
     
       
         
           
           
         

       

     

   


in both project and 

 

on the server end.


Nothing fixed.


After test piece by piece, found here is the point that causing this error:


        [System.Xml.Serialization.XmlElementAttribute("xxxxxxxxxxCOU", typeof(xxxxxxxCOUType))]
        [System.Xml.Serialization.XmlElementAttribute("xxxxxxxxxxNew", typeof(xxxxxxxNewType))]
        [DataMember]
        public object Item
        {
            get
            {
                return this.itemField;
            }
            set
            {
                this.itemField = value;
            }
        }


this is a field inside a class.


Note: in order to import all the classes and its fields, methods, need to add [DataContract] at the top of the class and [DataMember] at top of all public fields.


It is not passing the possible types to the test program.

In order to inform test program about it, we need to add the following to the top of the class (Notice:not the field, but the class)

[KnownType(typeof(xxxxxxxCOUType))]
[KnownType(typeof(xxxxxxxNewType))]


Then, the test program would recognize object item which type it is.

你可能感兴趣的:(bug,record)