Datacontract and WCF Dynamic Return Type

I have ServiceContractone that returns a dynamic type and looks like this:

public dynamic LoginViaOpenId(string openIdUrl)

The type of dynamic return may be DataContractthat I defined, or a string. But since I did not use mine DataContractin the service, the client knows nothing about this and cannot access it.

My DataContractlooks like this:

[DataContract]
public enum OpenIdStatus
{
        [EnumMember]
        Authenticated,
        [EnumMember]
        Authenticating,
        [EnumMember]
        Cancelled,
        [EnumMember]
        Failed,
        [EnumMember]
        RedirectToLogon
 }

I know if I had hierarchical types that I could use KnownTypeto defeat this, but I don't know this scenario. Any idea?

+5
source share
2 answers

DataContract . DataContract - , dynamic - , , , , .

, , . , , - , . , "" ( " " ), WCF.

[OperationContract] [DataContract], -, object, [KnownType] - , . object, .

[DataContract]
[KnownType(typeof(OpenIdStatus))]
[KnownType(typeof(string))]
public class ReturnValue
{
    [DataMember]
    public object Value { get; set; }
}
+16

All Articles