【问题标题】:WCF Service: File upload ends in Protocol exception: MaxArraylength exceededWCF 服务:文件上传以协议异常结束:超出 MaxArraylength
【发布时间】:2018-10-26 01:21:23
【问题描述】:

我现在正在编写一个webservice,用法如下:

我有一个 dll 的前端,这意味着我有一个带有 wpf 窗口的库项目。 该库应从其他程序中调用。 后端 WCF 服务托管在外部 IIS 上,前端通过引用 wcf 服务的 controller.dll 调用 Web 服务方法。

我在这里和谷歌已经阅读了几篇关于相同问题的帖子......但我无法修复它。

我有一个虚拟的 windows 窗体,它调用 frontend.dll。 那个项目得到了那个 app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
            allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
            maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
            messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
            useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
              maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
                realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://Hidden-ip/TicketReportService.svc"
          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
          contract="ServiceReference.IService" name="BasicHttpBinding_IService" />
    </client>
  </system.serviceModel>
</configuration>

我知道,如果我按照我在此处描述的方式进行操作,每个想要调用我的 frontend.dll 的程序都需要将绑定/端点配置放在他们自己的 app.config 中。 这只是一个例子,后来我在我的 controller.dll 中以编程方式进行绑定/端点配置,所以我不需要配置文件......但那是另一个话题。

如果我调用我的方法,通过网络服务上传文件,我有两种情况:

如果文件 > 16kb 和 "MaxArrayLength" (16384) was exceeded。

如果我尝试上传大约 60kb 的文件,我也会收到协议异常,但仅包含以下信息:“remoteserver returned unexpected answer.(400) bad request.

如果您查看 app.config,maxarray 长度设置为 int32.max 值。 此外,如果我检查调用该方法的对象的绑定,它会告诉我 maxarraylength 是从 app.config 中获取的......但我仍然收到错误消息。

我在这里做错了什么? 那是客户端的问题,我不是吗?

在 IIS 上的服务 web.config 中,我得到以下信息:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <services>
            <service behaviorConfiguration="BackendService.Behavior" name="MyNamespaye.Service">
                <endpoint address="" binding="basicHttpBinding" contract="MyNamespaye.IService" />
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="BackendService.Behavior">
                    <serviceMetadata httpGetEnabled="true"/>
                    <serviceDebug includeExceptionDetailInFaults="false" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>
    <connectionStrings>
        <add name="CustomerEntities" connectionString="metadata=res://*/CustomerModel.csdl|res://*/CustomerModel.ssdl|res://*/CustomerModel.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=hidden-ip;User Id=root;database=fromcloud;password=hidden-pw;Persist Security Info=True&quot;" providerName="System.Data.EntityClient" />
        <add name="DocumentEntities" connectionString="metadata=res://*/DocumentModel.csdl|res://*/DocumentModel.ssdl|res://*/DocumentModel.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=hidden-ip;User Id=root;password=hidden-pw;Persist Security Info=True;database=fromcloud&quot;" providerName="System.Data.EntityClient" />
    </connectionStrings>
</configuration>

【问题讨论】:

    标签: wcf iis file-upload


    【解决方案1】:

    ...自己修好了。不知道还要在服务端配置!

    新的 web.config:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="BasicHttpBinding_IService" closeTimeout="00:10:00"
                        openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
                        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                        maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
                        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                        useDefaultWebProxy="true">
                        <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
                            maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                        <security mode="None">
                            <transport clientCredentialType="None" proxyCredentialType="None"
                                realm="" />
                            <message clientCredentialType="UserName" algorithmSuite="Default" />
                        </security>
                    </binding>
                </basicHttpBinding>
            </bindings>
            <services>
                <service behaviorConfiguration="BackendService.Behavior" name="MyNamespace.Service">
                  <host>
                      <baseAddresses>
                        <add baseAddress="http://localhost:1111/"/>
                      </baseAddresses>
                </host>
                 <endpoint address="http://MyIP/TicketReportService.svc"
                      binding="basicHttpBinding" 
                      bindingConfiguration="BasicHttpBinding_IService"
                      contract="Mynamespace.BackendService.IService" 
                      name="ticketReport_endpoint" />
    
                </service>
            </services>
            <behaviors>
                <serviceBehaviors>
                    <behavior name="BackendService.Behavior">
                        <serviceMetadata httpGetEnabled="true"/>
                        <serviceDebug includeExceptionDetailInFaults="false" />
                    </behavior>
                </serviceBehaviors>
            </behaviors>
        </system.serviceModel>
        <connectionStrings>
            <add name="CustomerEntities" connectionString="metadata=res://*/CustomerModel.csdl|res://*/CustomerModel.ssdl|res://*/CustomerModel.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=fwefwef;User Id=root;database=fromcloud;password=fwefw;Persist Security Info=True&quot;" providerName="System.Data.EntityClient" />
            <add name="DocumentEntities" connectionString="metadata=res://*/DocumentModel.csdl|res://*/DocumentModel.ssdl|res://*/DocumentModel.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=fwefwef;User Id=root;password=fwef;Persist Security Info=True;database=fromcloud&quot;" providerName="System.Data.EntityClient" />
        </connectionStrings>
    </configuration>
    

    ...刚刚又做了一次谷歌搜索,找到了一个合适的 web.config 示例。 无论如何,感谢任何阅读 OP 的人。

    【讨论】:

      猜你喜欢
      • 2011-02-21
      • 1970-01-01
      • 2011-10-04
      • 2011-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-09
      相关资源
      最近更新 更多