开发者

The underlying connection was closed: The connection was closed unexpectedly

开发者 https://www.devze.com 2022-12-11 03:29 出处:网络
When working with WCF many times the exception massage doesn’t help us to solve the problem. The above massage is usually a symptom for one of the following problems:

When working with WCF many times the exception massage doesn’t help us to solve the problem. The above massage is usually a symptom for one of the following problems:

  1. The return values are bigger than the value which was defined in the config file.
  2. There is a problem with the endpoint setting
  3. There is a problem with serialization of the data

I experienced the 3rd problem which was with enums The problem was that the an enum was defined explicitly with values

  Public Enum FrequencyEnums
        EveryTime = 1
        OncePerHour = 2
        OncePerDay = 3
        OncePerWeek = 4
        Never = 5
    End Enum

And the private property that was using this enum was defined as follows

Private m_sendFrequencyID As FrequencyEnums

Now because the enum does not have a definition of a default value and because the property is not initialized explicitly and because the enum value for 0 is missing from the enum and because the default value of enum regardless of the specified options is always 0 When I tried to return instance of this class to the client I got this error: The underlying connection was closed: The connection was closed unexpectedly

The solution is one of the following:

  1. Define 0 value for enums or
  2. Define a default value for a property from the enum values.
  3. Assign initial value to the property

My question is how could I 开发者_运维百科have found this error with Microsoft tools and not by trial and error?


Found this a while ago trying to resolve the same error message (I had a different issue). Enabling trace and use svctraceviewer.exe to look at the trace log helped me a lot. Please see the following URL for more information: Enable WCF Trace Log


You need to create a data contract for the enum. See: http://consultingblogs.emc.com/merrickchaffer/archive/2007/04/03/Passing-Enum-values-into-WCF-Service-operations.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号