0

C# dll から WCF サービスを参照しているため、生成された app.config ファイルが読み取られません。以下のコードを使用して手動でサービス クライアントを作成しようとしています。ただし、MaxItemsInObjectGraph を増やす必要があるというエラーが発生しています。実行中のサービスは既に int.MaxValue に設定されているため、TestServiceClient でそれを増やす必要があります。何か案は??前もって感謝します!

var client = new TestServiceClient(GetBinding(), GetEndpointAddress());

private static EndpointAddress GetEndpointAddress()
        {
            var endpoint = new EndpointAddress("https://localhost:8000/ServiceModel/service");

            return endpoint;
        }

        private static Binding GetBinding()
        {
            var basicHttpBinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport)
            {
                MessageEncoding = WSMessageEncoding.Text,
                TextEncoding = Encoding.UTF8,
                BypassProxyOnLocal = false,
                UseDefaultWebProxy = true,
                CloseTimeout = new TimeSpan(10, 0, 0),
                OpenTimeout = new TimeSpan(10, 0, 0),
                SendTimeout = new TimeSpan(10, 0, 0),
                ReceiveTimeout = new TimeSpan(10, 0, 0),
                HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
                MaxBufferPoolSize = Int32.MaxValue,
                MaxReceivedMessageSize = Int32.MaxValue,
                AllowCookies = false,
                TransferMode = TransferMode.StreamedResponse,
                ReaderQuotas =
                {
                    MaxDepth = 32,
                    MaxStringContentLength = Int32.MaxValue,
                    MaxArrayLength = 6553600,
                    MaxBytesPerRead = 4096,
                    MaxNameTableCharCount = 16384
                }
            };

            return basicHttpBinding;
        }

以下は私の解決策です:

private static ITestServiceClient GetClient()
        {
            var factory = new ChannelFactory<ITestServiceClient >(GetBinding(), GetEndpointAddress());

            foreach (var dataContractBehavior in factory.Endpoint.Contract.Operations
                .Select(operation => operation.Behaviors.Find<DataContractSerializerOperationBehavior>())
                .Where(dataContractBehavior => dataContractBehavior != null))
            {
                dataContractBehavior.MaxItemsInObjectGraph = Int32.MaxValue;
            }

            var client = factory.CreateChannel();

            return client;
        }
4

1 に答える 1

2

client.Endpoint.Contract.Operations で試してください

foreach (var operation in operations)
{
   var dataContractBehavior = operation.Behaviors.Find<DataContractSerializerOperationBehavior>();
   if (dataContractBehavior != null)
   {
      dataContractBehavior.MaxItemsInObjectGraph = value;
   }
}
于 2012-10-10T14:01:23.470 に答える