在 WCF 服务中,我需要根据条件发送 DataMember。怎么做?
In WCF Service, I need to send the DataMember based on the condition. How to do that?
例如:
Public class TEST
{
[DataMember]
public string EMPName
{
get; set;
}
}
我需要 EMPName 作为输出响应对象的一部分,但基于某些条件,我需要在调用的服务函数中写入该条件。
例如:如果 EMPName 包含 'Jolie' 则仅将其保留为输出对象的一部分,否则不要将其与输出对象一起发送。
在您的 TEST 类中使用 ShouldSerialize 属性。
在您的 TESTclass 中包含以下行:
public bool ShouldSerializeEMPName() { return EMPName.Contains("Jolie"); }
希望对您有所帮助
例如:
Public class TEST
{
[DataMember]
public string EMPName
{
get; set;
}
}
我需要 EMPName 作为输出响应对象的一部分,但基于某些条件,我需要在调用的服务函数中写入该条件。
例如:如果 EMPName 包含 'Jolie' 则仅将其保留为输出对象的一部分,否则不要将其与输出对象一起发送。
在您的 TEST 类中使用 ShouldSerialize 属性。 在您的 TESTclass 中包含以下行:
public bool ShouldSerializeEMPName() { return EMPName.Contains("Jolie"); }
希望对您有所帮助