c# - 基础连接已关闭

标签 c# web-services properties

我花了几个小时弄清楚为什么会收到以下消息:

底层连接已关闭:服务器关闭了预期保持事件状态的连接。

我发现每当网络服务尝试发送具有基本获取/设置的属性时,我都会收到此消息。

例子:

public string Name {get;set;} //Works without problems

public string Name { get { return "test"; } } //Fails

第一次尝试时出现以下错误:

The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.

如果我再试一次,它会给我以下错误:

An error occurred while receiving the HTTP response to http://localhost/webapi3/ProductData.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

在我的跟踪日志中,我发现以下错误:No set method for property 'test' in type 'PS.Converter.ApiModel.DefaultBase'

这是否意味着在使用 WCF 时属性必须始终有一个集合?或者这是某种可配置的方式?

最佳答案

该属性必须在 WCF 中有一个 setter - 否则数据协定序列化程序无法反序列化它。如果您不希望该字段被序列化,您可以向其添加 IgnoreDataMember 属性。

如果您需要该属性只读,只需添加一个私有(private) setter。

关于c# - 基础连接已关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15218868/

相关文章:

c# - 如何从实体类型查找 NHibernate 实体的表映射?

web-services - 在没有加密的情况下通过网络向用户发送 SSL-pubkey 是否安全?

java - 字符串参数通常在网络服务中自动转义吗?

PHP Soap xml 与 SoapUI xml

PHP 扩展类使子级继承相同的静态属性

Visual Studio 2015 CTP 6 中的 C# 交互窗口

c# - 使用 NetCore.MailKit 发送电子邮件时地址的 ArgumentNullException

c# - Jpg 内容类型

c# - 如何实现虚拟静态属性?

javascript - 替换 JavaScript 文件中的 Maven Archetype 属性