底层连接已关闭:连接意外关闭

发布于 2024-08-09 15:33:36 字数 706 浏览 3 评论 0原文

当多次使用WCF时,异常按摩并不能帮助我们解决问题 问题。上述消息通常是以下问题之一的症状:

  1. 返回值大于配置文件中定义的值。
  2. 端点设置有问题
  3. 数据序列化有问题

我遇到的第三个问题与枚举有关 问题是枚举是用值显式定义的

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

并且使用该枚举的私有属性定义如下

Private m_sendFrequencyID As FrequencyEnums

现在因为枚举没有默认值的定义并且 因为该属性没有显式初始化并且 因为枚举中缺少 0 的枚举值,并且 因为无论指定的选项如何,enum 的默认值始终为 0 当我尝试将此类的实例返回给客户端时,出现以下错误: 基础连接已关闭:连接意外关闭

解决方案是以下方法之一:

  1. 为枚举定义 0 值或
  2. 根据枚举值为属性定义默认值。
  3. 为属性分配初始值

我的问题是如何使用 Microsoft 工具而不是通过反复试验发现此错误?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愛上了 2024-08-16 15:33:36

不久前发现了这个问题,试图解决相同的错误消息(我有一个不同的问题)。启用跟踪并使用 svctraceviewer.exe 查看跟踪日志对我帮助很大。请参阅以下网址了解更多信息:
启用 WCF 跟踪日志

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文