1

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

1 に答える 1

0

コードに問題はありません。問題は応答によるものでした。List プロパティを保持するカスタム ストリームでした。これはサポートされておらず、自動的にバッファリングに切り替えられます。そのため、リストをメッセージヘッダーとともに返されるように移動し、すべて正常に機能しました。

于 2015-04-07T15:00:20.587 に答える