将Config移动到代码后,将缓冲WCF流式响应

时间:2011-06-21 13:09:41

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

我有使用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;
    }

1 个答案:

答案 0 :(得分:0)

确定代码没问题,问题来自响应,它是一个包含List属性的自定义流,不支持此功能,它将自动切换为缓冲。所以移动列表返回消息标题,一切正常。