views:

25

answers:

1

I have a WCF REST Service:

[ServiceContract]
public IService
{
    [WebGet]
    [OperationContract]
    Data GetData(UserInfo userInfo);
}

UserInfo is a class:

public class UserInfo
{
    public string UserName { get; set; }
    public string Password { get; set; }
}

I want UserName and Password properties be filled from specific HTTP Headers but not from request body. How could I implement this?

+1  A: 

WCF offers some extensibility points which could be helpful for this scenario. I suggest you should check IParameterInspector or IOperationInvoker. Both can work with input parameters. Then you will have to create IOperationBehavior as Attribute and mark your method with this attribute. But I expect this scenario will have one more bigger problem. You are using WebGet and complex type and you don't have any Uri template which will map to parameters - it is not possible. WebGet operations can use only parameters with basic types and when you create such parameter in operation it has to be mentioned in Uri template or exception is fired.

Ladislav Mrnka