我有客户端服务器应用程序使用带有流式响应服务的 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;
}