3

I've spend some hours figuring out why I get the following message:

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

I've found out that I get this message whenever the webservice attempts to send a property with does have a basic get / set.

Example:

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

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

At first attempt it gives me the following error:

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

If I try it again it gives me the following error:

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.

In my tracelog I find the following error: No set method for property 'test' in type 'PS.Converter.ApiModel.DefaultBase'

Does this mean a property MUST have a set at all times when using WCF? Or is this is some way configurable ?

4

2 に答える 2

1

プロパティには、WCF のセッターが必要です。そうでない場合、データ コントラクト シリアライザーはそれを逆シリアル化できません。フィールドをシリアル化したくない場合は、IgnoreDataMember 属性を追加できます。

プロパティを読み取り専用にする必要がある場合は、プライベート セッターを追加するだけです。

于 2013-03-05T08:39:05.673 に答える
0

プライベート セッターを提供できます。私が間違っていない限り、それは(逆)シリアル化可能にする必要がありますが、値が上書きされないようにします:

public string Name { 
    get { return "test"; }
    private set{}
} 
于 2013-03-05T09:53:00.393 に答える