2

我最近更改了绑定配置以允许在我的 WCF 服务中进行模拟。通过实现这一点,我需要使用缓冲的 TransferMode.Buffered 而不是流式传输。虽然这似乎暂时解决了我的问题,但我注意到大文件 (>200MB) 在尝试分配 MemoryStream 以传递消息时会引发异常。我的同事和 google 让我相信 Chunking 是答案,我已经尝试实现这个示例的一个版本:

MSDN 分块文章

我修改了 TCPChunkingBinding 类以从 BasicHttpBinding 而不是 Binding 派生,并添加了我们在尝试分块之前使用的必要 BasicHttpSecurity 属性。

以前使用 BasicHttpBinding 的所有端点现在都使用 TCPChunkingBinding。以下是我对 TCPChunkingBinding 类所做的修改:

TcpChunkingBinding : BasicHttpBinding, IBindingRuntimePreferences

...

void Initialize()
    {
        be = new ChunkingBindingElement();
        tcpbe = new TcpTransportBindingElement();
        tcpbe.TransferMode = TransferMode.Buffered; //no transport streaming
        tcpbe.MaxReceivedMessageSize = ChunkingUtils.ChunkSize + 100 * 1024; //add 100KB for headers
        this.MessageEncoding = WSMessageEncoding.Mtom;
        this.SendTimeout = new TimeSpan(0, 5, 0);
        this.ReceiveTimeout = this.SendTimeout;
        this.TransferMode = TransferMode.Buffered;

        BasicHttpSecurity security = new BasicHttpSecurity();
        security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
        security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
        security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
        security.Transport.Realm = string.Empty;
        security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
        security.Message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default;
        this.Security = security;

我得到的错误是

The contract operation 'DownloadStream' requires Windows identity for automatic impersonation. A Windows identity that represents the caller is not provided by binding ('TcpChunkingBinding','http://tempuri.org/') for contract ('ITestService','http://tempuri.org/'.

当我在示例中的 Service 类的 Host.cs 中调用 host.open() 时。

基本上我的问题是有人能帮我弄清楚如何让这个样本与模拟和分块一起工作吗?

在任何人回答之前,在尝试分块道路之前,我已将每个缓冲区设置都最大化,并且由于模拟的必要性,我无法使用 Streaming 传输模式。提前致谢。

4

0 回答 0