2017-02-13 118 views
0

我需要代码的参数在WCF客户端中设置ServiceBehaviorAttribute?

ServiceBehaviorAttribute

private static BasicHttpBinding getBinding()//BasicHttpBinding getBinding() 
{ 

    //WSHttpBinding binding = new WSHttpBinding(); 
    //WSHttpBinding binding = new WSHttpBinding(); 
    BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); 

    binding.TextEncoding = System.Text.Encoding.UTF8; 
    binding.ReaderQuotas.MaxArrayLength = int.MaxValue; 

    binding.ReceiveTimeout = new TimeSpan(8, 0, 0); 
    binding.SendTimeout = new TimeSpan(8, 0, 0); 

    binding.MaxReceivedMessageSize = int.MaxValue; 
    binding.MaxBufferSize = int.MaxValue; 
    binding.MaxBufferPoolSize = int.MaxValue; 


    binding.ReaderQuotas.MaxDepth = 64; 
    binding.ReaderQuotas.MaxArrayLength = int.MaxValue; 
    binding.ReaderQuotas.MaxStringContentLength = int.MaxValue; 

    return binding; 
} 


private static EndpointAddress getEndPoint() 
{ 
    EndpointAddress endPoint = new EndpointAddress(HTTP_SERVER); 
    return endPoint; 
} 


ConnectionToServer = new ConnectionToServer (getBinding(), new EndpointAddress(HTTP_SERVER)); 

热在ConnectionToServer这个代码中插入设置???

ServiceBehaviorAttribute sba = new ServiceBehaviorAttribute(); 
sba.MaxItemsInObjectGraph = int.MaxValue; 

回答

1

有一点是端点配置(即您发布的代码),另一个完全不同的是服务行为。

要设置SBA.MaxItemsInObjectGraph,您需要在通过WCF服务中的ServiceBehaviorAttribute(而不是您的代码所暗示的客户端)完成的服务协定的执行行为中指定它。

即:

[ServiceBehavior(
    InstanceContextMode = InstanceContextMode.Single, 
    ConcurrencyMode = ConcurrencyMode.Reentrant, 
    MaxItemsInObjectGraph = 34)] 
public class WcfService : IDuplexService 
{ 
    //service implementation goes here 
} 

这里是你如何可以在设定的ChannelFactory MaxItemsInObjectGraph:

 DuplexChannelFactory<IService> cf = new DuplexChannelFactory<IService>(typeof(ServiceCallback), Server.ServerBinding(), ep); 

     foreach (OperationDescription operation in cf.Endpoint.Contract.Operations) 
     { 
      var dc = operation.Behaviors.Find<DataContractSerializerOperationBehavior>(); 
      if (dc != null) 
      { 
       dc.MaxItemsInObjectGraph = int.MaxValue; 
      } 
     } 
+0

我只是回答您的问题一个又一个。 –