c# - 控制台应用程序中 WCF 托管服务中的 MaxReceivedMessageSize

标签 c# wcf windows-runtime wcf-binding

我的控制台应用程序中有一个托管 WCF 服务,如下所示:

static void Main(string[] args)
    {
        Uri baseAddress = new Uri("http://localhost:8080/Test");
        // Create the ServiceHost.
        using (ServiceHost host = new ServiceHost(typeof(TestService), baseAddress))
        {
            // Enable metadata publishing.
            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
            smb.HttpGetEnabled = true;
            smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
            host.Description.Behaviors.Add(smb);

            host.Open();

            Console.WriteLine("The Test service is ready at {0}", baseAddress);
            Console.WriteLine("Press <Enter> to stop the service.");



            Console.ReadLine();

            // Close the ServiceHost.
            host.Close();
        }  
    }

我在 Windows 应用商店 (WinRT) 应用程序中有一个客户端。我得到了

"(413) Request Entity Too Large"

当试图传递一个大字节数组时。如何通过代码在我的服务中设置 MaxReceivedMessageSize

最佳答案

需要创建一个Binding,然后指定MaxReceivedMessageSize:

Uri baseAddress = new Uri("http://localhost:8080/Test");
var serviceHost = new ServiceHost(typeof(TestService));
var basicHttpBinding = new BasicHttpBinding();
basicHttpBinding.MaxReceivedMessageSize = int.MaxValue;
serviceHost.AddServiceEndpoint(typeof(IService), basicHttpBinding, baseAddress);

关于c# - 控制台应用程序中 WCF 托管服务中的 MaxReceivedMessageSize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15850690/

相关文章:

c# - 内存不足故障自动化 VSTO Powerpoint API

c# - NSubstitute 模拟 Mongo IFindFluent 不起作用

wcf - 从 Silverlight 调用 WCF 时发生 CommunicationException

c# - 嵌套的 DataContract 序列化异常 WCF

c# - 在与服务线程不同的线程上运行服务操作

c# - 检查更新结果失败

c# - WSS3 - 创建后在 SPFieldType.Boolean 上设置默认值

c# - 在 Metro 应用程序中将数组从 javascript 传递到 C#

c# - ColorAnimation 为滑动时的 listviewItem 颜色设置动画 - WP8.1

windows-runtime - 如何使 C# Windows 运行时组件类型相等?