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

来源:互联网 发布:js获取手机滚动条位置 编辑:程序博客网 时间:2024/06/05 17:23

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:

  <bindings>
      <wsHttpBinding>
        <binding name="wsHttpBinding" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
          <security mode="Message">
            <!--<transport clientCredentialType="None" proxyCredentialType="None"/>-->
            <message clientCredentialType="UserName" negotiateServiceCredential="false"/>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>


in both project and 

 <sessionState mode="InProc" cookieless="false" timeout="40" sessionIDManagerType="BotDetect.Web.CustomSessionIdManager, BotDetect" />

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.

0 0
原创粉丝点击