WCF传递Stream时,同时传递其它参数的问题
刚开始学习wcf,遇到一个问题,就是如果我想在服务器端定义一个有两个参数的方法,一个参数为Stream,另一个为string或其它类型,访问WCF时就会报出这个错误:
[InvalidOperationException: 要使操作 GetName 中的请求成为流,操作必须具有其类型为 Stream 的单个参数。]
这个是我服务器端接口的写法:
[ServiceContract]public interface ITestService{ [OperationContract] [WebInvoke(Method = "POST")] Stream GetName(Stream name,string inputStr);}public class TestService:ITestService{ public TestService() { // // TODO: Add constructor logic here // } public Stream GetName(Stream name,string inputStr) { var sr = new StreamReader(name); string text = sr.ReadToEnd(); return new System.IO.MemoryStream(Encoding.UTF8.GetBytes("Test Service: "+" inputStr: "+inputStr+ text)); }}[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; } } }