WCF: Passing a value type parameter to an operation that returns a message contract

792 Views Asked by At

THE SITUATION:

I have this service contract:

[ServiceContract(ProtectionLevel = ProtectionLevel.EncryptAndSign)]
public interface IMyServiceContract
{
    //This WORKS! Because GUIDWRAPPER and Group have a MessageContract
    [OperationContract]
    Group GetA(GUIDWRAPPER id);

    //This DOES NOT WORK, because int has no MessageContract!
    [OperationContract]
    Group GetB(int id);
}

In this case Group has a message contract and this message contract inherits the security level from the service contract. Group looks like this:

[MessageContract]
public class Group: Entity, ICloneable
{
    public Group(){}

    [MessageBodyMember]
    public String Name {get;set;}
}

The type GUIDWRAPPER is a simple wrapper für a Guid, which also has a message contract:

[MessageContract]
public class GUIDWRAPPER
{
    public GUIDWRAPPER() { }

    public GUIDWRAPPER(Guid id)
    {
        Id = id;
    }

    [MessageBodyMember]
    public Guid Id { get; set; }
}

THE PROBLEM:

When I startup my service host, it complains that the operation "GetB" is invalid, because the return type "Group" has a message contract and the value type "int" has not. That's a possible security flaw.

"GetA" makes no problems because both, return type and parameter type, have message contracts.

POSSIBLE SOLUTIONS:

1.) I could wrap all value types, like I did with the GUIDWRAPPER class, and give them a message contract. But that feels dirty and smelly to me.

2.) Delete all message contracts and just go with data contracts. Then I lose control, which data is sent and received.

MY QUESTION:

Is it possible to pass a simple value type (like int in this case) to a service operation, which has a message contract return type? (like GetB in this case)

Are there any attributes for the operation contract to allow that?

0

There are 0 best solutions below