2015-10-20 62 views
0

我在應用程序的服務端有一個poco。我想將這個對象傳遞給客戶端,但沒有一些特定的屬性。將對象從WCF服務傳輸到客戶端時忽略一些屬性

將結果返回給客戶端時,有沒有辦法「隱藏」某些屬性?

我已經嘗試[IgnoreDataMember],[IgnoreProperties(「xxx」)],[NonSerialized]和許多其他屬性沒有運氣......有沒有辦法做到這一點?

+0

請分享您的代碼 – Nostradamus

+0

您在服務方面有什麼Soap/Rest? – vendettamit

+0

@michelqa Ignore是什麼意思?你的意思是你想完全從Soap消息回覆中拿出來,或者只是發出被忽略的屬性的默認值? – vendettamit

回答

1

您的WCF服務必須在poco類上使用DataContract,從屬性中刪除[DataMember]屬性,並且該屬性應該有效。例如,BoolValue不會成爲合同的一部分。

[DataContract] 
public class CompositeType 
{ 
    bool boolValue = true; 
    string stringValue = "Hello "; 

    //Not a part of contract 
    public bool BoolValue 
    { 
     get { return boolValue; } 
     set { boolValue = value; } 
    } 

    [DataMember] 
    public string StringValue 
    { 
     get { return stringValue; } 
     set { stringValue = value; } 
    } 
} 
+0

謝謝這就是我需要的! – michelqa

相關問題