Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过WCF将文件流从客户端传递到服务器_C#_Wcf_Stream - Fatal编程技术网

C# 通过WCF将文件流从客户端传递到服务器

C# 通过WCF将文件流从客户端传递到服务器,c#,wcf,stream,C#,Wcf,Stream,我需要将文件流从客户端传递到服务器 服务器端是: [ServiceContract] public interface IDocumentService { [OperationContract] void ValidateXml(Stream stream); } public class DocumentService : IDocumentService { public void ValidateXml(Stream stream) {

我需要将
文件流
从客户端传递到服务器

服务器端是:

[ServiceContract]
public interface IDocumentService
{
     [OperationContract]
     void ValidateXml(Stream stream);
}

public class DocumentService : IDocumentService
{
     public void ValidateXml(Stream stream)
     {
        if(stream != null)
        {
           stream.Seek(0, SeekOrigin.Begin);
           var reader = XmlReader.Create(stream);
           var doc = XDocument.Load(reader);
           doc.Validate(schema, ValidateEventHadler);           
        }
     }

     private static void ValidationEventHandler(object sender, ValidationEventArgs e)
     {
         throw e.Exception;
     }
}
客户端:

private void LoadXml_Click(object sender, EventArgs e)
{
            var fileDialog = new OpenFileDialog {Filter = @"xml files (*.xml)|*.xml"};
            if (fileDialog.ShowDialog() != DialogResult.OK) return;
            try
            {
                using (Stream fs = new FileStream(fileDialog.FileName, FileMode.Open))
                {                    
                    Stream ms = new MemoryStream();
                    fs.CopyTo(ms);

                Proxy.ValidateXml(ms);
            }       
        }
        catch (Exception ex)
        {
            ErrorDialog.Show(ex);
        }
    }
当我发送流时,它是空的。 服务器在本地网络中,我找到了这篇文章,但实际上我不知道该如何使用这种方法:

public static Binding CreateStreamingBinding()
{
    TcpTransportBindingElement transport = new TcpTransportBindingElement();
    transport.TransferMode = TransferMode.Streamed;
    BinaryMessageEncodingBindingElement encoder = new BinaryMessageEncodingBindingElement();
    CustomBinding binding = new CustomBinding(encoder, transport);
    return binding;
}
需要帮忙吗