1

我有客户端服务器应用程序使用带有流式响应服务的 net.tcp 绑定,所有 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;
    }
4

1 回答 1

0

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

于 2015-04-07T15:00:20.587 回答