WCF流式响应在将Config移动到代码后进行缓冲
本文关键字:代码 缓冲 移动 Config 响应 WCF | 更新日期: 2023-09-27 17:59:56
我有一个客户端-服务器应用程序,它使用带有streamedResponse服务的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;
}
ok代码中没有问题,问题来自响应,它是一个拥有List属性的自定义流,这是不支持的,它将自动切换到缓冲区。因此移动列表以返回消息头,所有操作都很好。