简体   繁体   English

在WCF客户端中设置ServiceBehaviorAttribute?

[英]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.

相关问题 如何在多线程WCF Web服务中正确使用ServiceBehaviorAttribute.InstanceContextMode? - how to use ServiceBehaviorAttribute.InstanceContextMode correctly in multithreaded WCF Web Service? 如何为特定的 wcf 客户端设置代理凭据? - How to set proxy credentials to specific wcf client? 在WCF客户端回调绑定上设置SendTimeout? - Set the SendTimeout on a WCF client callback binding? WCF-从客户端代码设置端点 - WCF - set endpoint from client code 如何在WCF客户端中设置HTTP代理的凭据 - How to set credentials for HTTP Proxy in WCF Client 如何在代码中使用wsDualHttpBinding设置WCF客户端? - How to set up a WCF client using wsDualHttpBinding in code? 我必须在WCF客户端和服务器上设置相同的SecurityMode吗? - Do I have to set the same SecurityMode on WCF Client and Server? 如何使用配置在 WCF 客户端上设置用户名/密码? - How do you set a username / password on a WCF Client using configuration? 代理设置设置为“使用自动配置脚本”的 WCF 客户端 - WCF client with proxy settings set to “Use automatic configuration script” WCF服务客户端应用程序获取“对象未设置为对象的实例” - WCF service client application getting “Object not set to an instance of an object”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM