[英]Set ServiceBehaviorAttribute in WCF Client?
I need to set by code the parameter 我需要通过代码设置参数
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));
Hot to insert in the ConnectionToServer
this code ??? 可以在
ConnectionToServer
插入此代码?
ServiceBehaviorAttribute sba = new ServiceBehaviorAttribute();
sba.MaxItemsInObjectGraph = int.MaxValue;
One thing is the endpoint configuration (ie the code you posted) and another completely different thing is the service behavior. 一件事是端点配置(即,您发布的代码),另一件事是服务行为。
To set SBA.MaxItemsInObjectGraph you need to specify it in the execution behavior of the service contract which is done via a ServiceBehaviorAttribute in the WCF Service (not the client as your code implies). 要设置SBA.MaxItemsInObjectGraph,您需要在服务合同的执行行为中指定它,这是通过WCF服务中的ServiceBehaviorAttribute(不是您的代码所暗示的客户端)完成的。
ie: 即:
[ServiceBehavior(
InstanceContextMode = InstanceContextMode.Single,
ConcurrencyMode = ConcurrencyMode.Reentrant,
MaxItemsInObjectGraph = 34)]
public class WcfService : IDuplexService
{
//service implementation goes here
}
Here's how you can set MaxItemsInObjectGraph on a ChannelFactory: 以下是在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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.