WCF OperationContract and Dynamic Parameter

I have a WCF service based on Writing Highly Reliable WCF Services . Requests are processed using CommandService:

[WcfDispatchBehaviour]
[ServiceContract(Namespace="http://somewhere.co.nz/NapaWcfService/2013/11")]
[ServiceKnownType("GetKnownTypes")]
public class CommandService
{
    [OperationContract]
    public object Execute(dynamic command)
    {
        Type commandHandlerType = typeof(ICommandHandler<>).MakeGenericType(command.GetType());
        dynamic commandHandler = BootStrapper.GetInstance(commandHandlerType);
        commandHandler.Handle(command);
        return command;
    }

    public static IEnumerable<Type> GetKnownTypes(ICustomAttributeProvider provider)
    {
        var coreAssembly = typeof(ICommandHandler<>).Assembly;
        var commandTypes =
            from type in coreAssembly.GetExportedTypes()
            where type.Name.EndsWith("Command")
            select type;

        return commandTypes.ToArray();
    }
}

Everything works fine (thanks to Steve), but now I need to add the ability to upload a file to the service. From the read and based on the errors received during testing, WCF should use [MessageContract]when downloading a file using Stream. So I graced my team class and put non-Stream members in the message header and updated the binding definition to use streaming:

[MessageContract]
public class AddScadaTileCommand
{
    [MessageHeader(MustUnderstand = true)]
    public int JobId { get; set; }

    [MessageHeader(MustUnderstand = true)]
    public string MimeType { get; set; }

    [MessageHeader(MustUnderstand = true)]
    public string Name { get; set; }

    [MessageBodyMember(Order = 1)]
    public Stream Content { get; set; }
}

Unfortunately, when I call the service with the file to download, I get the error message:

http://somewhere.co.nz/NapaWcfService/2013/11:command. InnerException "" System.IO.FileStream 'FileStream: http://schemas.datacontract.org/2004/07/System.IO' .

, :

[OperationContract]
public void Upload(AddScadaTileCommand addScadaTileCommand)
{
    Type commandHandlerType = typeof(ICommandHandler<>).MakeGenericType(typeof(AddScadaTileCommand));
    dynamic commandHandler = BootStrapper.GetInstance(commandHandlerType);
    commandHandler.Handle(addScadaTileCommand);
}

, AddScadaTileCommand dynamic , , . , [MessageContract] dynamic . , ?

+3

All Articles