当你的才华不能撑起你的野心时,就是你该选择学习的时候了!

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;
        }
    }   
}

 

posted @ 2020-07-20 14:42  hofmann  阅读(308)  评论(0编辑  收藏  举报