【问题标题】:MaxReceivedMessageSize in WCF Hosted Service in console application控制台应用程序中 WCF 托管服务中的 MaxReceivedMessageSize
【发布时间】:2013-04-06 12:02:11
【问题描述】:

我的控制台应用程序中有一个托管的 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) 请求实体太大”

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

【问题讨论】:

    标签: c# wcf windows-runtime wcf-binding


    【解决方案1】:

    你需要创建一个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);
    

    【讨论】:

      【解决方案2】:

      如果你的字节数组太大,那么你总是可以把它分成更小的块,然后循环发送。您甚至可能希望在另一个线程中执行此操作并更新用户界面的进度。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-07-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多