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;
}