WCF 操作调用中的大字符串参数

发布于 2024-11-08 05:02:13 字数 2295 浏览 2 评论 0原文

我无法将字符串作为参数传递给 WCF 操作调用。该字符串相当大(大约 12000 个字符)。

我在 web.config 中增加了 maxStringContentLength 并尝试了几乎所有属性,但问题仍然存在。

我找到了一种解决方法 - 在客户端拆分字符串并在服务器端连接。它是这样工作的。

有人能指导我解决这个问题的正确方法吗?为什么 WCF 操作调用能够接受相同数量的数据(分为 2 个字符串参数),但当该数据以一个字符串参数传递时会抛出错误?我们在哪里配置 WCF 操作参数的大小限制?

- - - - - - - - - - - - - - - - -代码 - - - - - - - - ----------------

TestService.Service1Client client = new TestService.Service1Client();
string str = "VERY LARGE STRING";

//DOES NOT WORK
client.TakeLargeStringParam(str);

//WORKS
client.TakeLargeStringParam2(str.Substring(0, 5000), str.Substring(5000));

----------------------WEB.CONFIG-------- ------------------

<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="819200" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:30701/Service1.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IService1" contract="TestService.IService1"
                name="BasicHttpBinding_IService1" />
        </client>
    </system.serviceModel>

I am unable to pass a string as an argument to a WCF operation call. The string is quite large (about 12000 characters).

I have increased maxStringContentLength in web.config and played around with almost all the attributes but the problem still remains.

I have found a workaround - Split the string at client's end and concatenate at the server's end. It works this way.

Can anybody direct me towards the right way of solving this problem? Why WCF operation call is able to accept the same amount of data (split into 2 string parameters) but throws error when that data is passed in one string parameter? Where do we configure the size limit of WCF operation arguments?

---------------------------------CODE--------------------------------

TestService.Service1Client client = new TestService.Service1Client();
string str = "VERY LARGE STRING";

//DOES NOT WORK
client.TakeLargeStringParam(str);

//WORKS
client.TakeLargeStringParam2(str.Substring(0, 5000), str.Substring(5000));

-----------------------WEB.CONFIG--------------------------

<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="819200" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:30701/Service1.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IService1" contract="TestService.IService1"
                name="BasicHttpBinding_IService1" />
        </client>
    </system.serviceModel>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流年里的时光 2024-11-15 05:02:13

您需要在服务器端而不是客户端增加 maxStringContentLength。 web.config 仅具有 部分,要配置服务,您需要在其中设置 部分。如果服务上没有匹配的服务配置,它将使用默认配置,该配置具有默认配额值。

You need to increase the maxStringContentLength at the server side, not at the client. The web.config only has a <client> section, and to configure a service you'd need to set a <service> section there. If there's no matching service configuration on the service, it will use a default one, which has the default quota values.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文