【问题标题】:WCF Streamed Response is buffered after moving Config to code将配置移动到代码后缓冲 WCF 流式响应
【发布时间】:2011-06-21 13:09:40
【问题描述】:

我有客户端服务器应用程序使用 net.tcp 绑定和 streamedResponse 服务,所有 WCF 配置都已在 app.config 中定义并且一切正常,没有问题,我必须从客户端应用程序中删除配置并将它们定义在代码,服务器上没有任何变化,但是客户端似乎将响应作为缓冲而不是通过此转换流式传输,这是我在客户端代码中构建服务的方式:

public static BuildChannelFactory()
{
channelFactorty = new ChannelFactory<IMyService>(GetStreamBinding(),
                   Address);


            channelFactorty .Endpoint.Address = new EndpointAddress(
                 new Uri(Address), EndpointIdentity.CreateDnsIdentity(
                 "MyServer"));


            channelFactorty.Credentials.ClientCertificate.SetCertificate(
                StoreLocation.LocalMachine, StoreName.Root,   
                X509FindType.FindBySubjectName,
               "MySubject");

            channelFactorty.Credentials.ServiceCertificate.
Authentication.CertificateValidationMode =  
System.ServiceModel.Security.X509CertificateValidationMode.Custom;

channelFactortyCredentials.ServiceCertificate.Authentication.
CustomCertificateValidator = MyCertificateValidator;    
}



private static NetTcpBinding GetStreamBinding()
    {

          NetTcpBinding streamBinding = new NetTcpBinding
            {
                Name = "streamBinding",
                ReceiveTimeout = new TimeSpan(2, 0, 0),
                SendTimeout = new TimeSpan(0, 2, 0),
                MaxBufferSize = int.MaxValue,
                MaxReceivedMessageSize = int.MaxValue,
                TransferMode = TransferMode.StreamedResponse,

                ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas
                {
                    MaxArrayLength = int.MaxValue,
                    MaxStringContentLength = int.MaxValue
                }

            };

            streamBinding .Security.Mode = SecurityMode.Transport;
            streamBinding .Security.Transport.ClientCredentialType =  
            TcpClientCredentialType.Certificate;
        }

        return streamBinding;
    }

【问题讨论】:

    标签: c# wcf-binding wcf-client wcf-streaming


    【解决方案1】:

    好的,代码没有问题,问题来自响应,它是一个包含 List 属性的自定义流,这是不支持的,它将自动切换到缓冲。所以将列表移动到与消息头一起返回并且一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-04
      • 1970-01-01
      • 2011-01-07
      • 1970-01-01
      相关资源
      最近更新 更多