控制台应用程序中 WCF 托管服务中的 MaxReceivedMessageSize [英] MaxReceivedMessageSize in WCF Hosted Service in console application

查看:24
本文介绍了控制台应用程序中 WCF 托管服务中的 MaxReceivedMessageSize的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a hosted WCF service in my console application as follow:

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) 应用程序中有一个客户端.我要了

I have a client in a Windows Store (WinRT) application. I'm getting

(413) 请求实体太大"

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

when trying to pass a large byte array. How can I set MaxReceivedMessageSize in my service by code?

推荐答案

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

You need to create a Binding, and then specify 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);

这篇关于控制台应用程序中 WCF 托管服务中的 MaxReceivedMessageSize的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆