WCF传递Stream时,同时传递其它参数的问题
[InvalidOperationException: 要使操作 GetName 中的请求成为流,操作必须具有其类型为 Stream 的单个参数。]
用MessageContract修饰的类作为参数。Stream声明在类里面。
C# code
[ServiceContract] public interface ITransferService { [OperationContract] RemoteFileInfo DownloadFile(DownloadRequest request); [OperationContract] void UploadFile(RemoteFileInfo request); } [MessageContract] public class DownloadRequest { [MessageBodyMember] public string FileName; } [MessageContract] public class RemoteFileInfo : IDisposable { [MessageHeader(MustUnderstand = true)] public string FileName; [MessageHeader(MustUnderstand = true)] public long Length; [MessageBodyMember(Order = 1)] public System.IO.Stream FileByteStream; public void Dispose() { if (FileByteStream != null) { FileByteStream.Close(); FileByteStream = null; } } }