WCF Streamed Response буферизируется после перемещения Config в код
У меня есть клиент-серверное приложение, использующее привязки 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 ответ
Решение
ОК, нет проблем в коде, проблема была в ответе, это был пользовательский поток, который содержит свойство List, это не поддерживается, и он будет переключен на буферизованный автоматически. поэтому переместил список для возврата с заголовком сообщения и все работало нормально.