2009-01-21 76 views
36

我正在编写一个小的WCF/WPF应用程序来调整图像大小,但当我尝试从客户端向我的服务发送大小为28K的图像时,WCF会给我带来麻烦。当我发送较小的图像时,该服务正常工作。我马上认为这是一个配置问题,并且我在绑定配置中浏览了关于MaxArrayLength属性的帖子。香港专业教育学院调升对客户端和服务器上的这些设置限制的最大2147483647,但我仍然得到以下错误:最大阵列长度限额

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://mywebsite.com/services/servicecontracts/2009/01:OriginalImage . The InnerException message was 'There was an error deserializing the object of type System.Drawing.Image. The maximum array length quota (16384) has been exceeded while reading XML data. This quota may be increased by changing the MaxArrayLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader.'. Please see InnerException for more details.

我做了我的客户端和服务器CONFIGS相同的,它们看起来像下面这样: 服务器:

<system.serviceModel> 
    <bindings> 
     <netTcpBinding> 
      <binding name="NetTcpBinding_ImageResizerServiceContract" closeTimeout="00:01:00" 
       openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
       transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" 
       hostNameComparisonMode="StrongWildcard" listenBacklog="10" 
       maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10" 
       maxReceivedMessageSize="2147483647"> 
       <readerQuotas maxDepth="32" 
           maxStringContentLength="2147483647" 
           maxArrayLength="2147483647" 
           maxBytesPerRead="2147483647" 
           maxNameTableCharCount="2147483647" /> 
       <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" /> 
       <security mode="Transport"> 
        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" /> 
        <message clientCredentialType="Windows" /> 
       </security> 
      </binding> 
     </netTcpBinding> 
    </bindings> 
    <behaviors> 
     <serviceBehaviors> 
      <behavior name="ServiceBehavior"> 
       <serviceMetadata httpGetEnabled="true" /> 
       <serviceDebug includeExceptionDetailInFaults="false" /> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <service name="LogoResizer.WCF.ServiceTypes.ImageResizerService" behaviorConfiguration="ServiceBehavior"> 
      <host> 
       <baseAddresses> 
        <add baseAddress="http://localhost:900/mex/"/> 
        <add baseAddress="net.tcp://localhost:9000/" /> 
       </baseAddresses> 
      </host> 
      <endpoint binding="netTcpBinding" contract="LogoResizer.WCF.ServiceContracts.IImageResizerService" /> 
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
     </service> 
    </services> 
</system.serviceModel> 

和我的客户端配置的样子:

<system.serviceModel> 
    <bindings> 
     <netTcpBinding> 
      <binding name="NetTcpBinding_ImageResizerServiceContract" closeTimeout="00:01:00" 
       openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
       transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" 
       hostNameComparisonMode="StrongWildcard" listenBacklog="10" 
       maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10" 
       maxReceivedMessageSize="2147483647"> 
       <readerQuotas maxDepth="32" 
           maxStringContentLength="2147483647" 
           maxArrayLength="2147483647" 
           maxBytesPerRead="2147483647" 
           maxNameTableCharCount="2147483647" /> 
       <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" /> 
       <security mode="Transport"> 
        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" /> 
        <message clientCredentialType="Windows" /> 
       </security> 
      </binding> 
     </netTcpBinding> 
    </bindings> 
    <client> 
     <endpoint address="net.tcp://localhost:9000/" binding="netTcpBinding" 
      bindingConfiguration="NetTcpBinding_ImageResizerServiceContract" 
      contract="ImageResizerService.ImageResizerServiceContract" 
      name="NetTcpBinding_ImageResizerServiceContract"> 
      <identity> 
       <userPrincipalName value="[email protected]" /> 
      </identity> 
     </endpoint> 
    </client> 
</system.serviceModel> 

似乎不管我设置这些值,我仍然得到一个埃罗r说wcf无法序列化我的文件,因为它大于16384.任何想法?

更新:中的UserPrincipalName标签的电子邮件地址已经改变了我的隐私

+0

考虑将自己的答案标记为正确。 :) – 2009-03-25 11:54:46

+0

ImageResizerService是什么?任何示例代码? – Kiquenet 2010-08-21 17:48:34

回答

38

我的坏 - 我忘了我的绑定配置适用于我在我的服务器端配置端点。服务器配置应为:

<system.serviceModel> 
    <bindings> 
     <netTcpBinding> 
      <binding name="NetTcpBinding_ImageResizerServiceContract" closeTimeout="00:01:00" 
       openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
       transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" 
       hostNameComparisonMode="StrongWildcard" listenBacklog="10" 
       maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10" 
       maxReceivedMessageSize="2147483647"> 
       <readerQuotas maxDepth="2147483647" 
           maxStringContentLength="2147483647" 
           maxArrayLength="2147483647" 
           maxBytesPerRead="2147483647" 
           maxNameTableCharCount="2147483647" /> 
       <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" /> 
       <security mode="Transport"> 
        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" /> 
        <message clientCredentialType="Windows" /> 
       </security> 
      </binding> 

     </netTcpBinding> 
    </bindings> 
    <behaviors> 
     <serviceBehaviors> 
      <behavior name="ServiceBehavior"> 
       <serviceMetadata httpGetEnabled="true" /> 
       <serviceDebug includeExceptionDetailInFaults="false" /> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <service name="LogoResizer.WCF.ServiceTypes.ImageResizerService" behaviorConfiguration="ServiceBehavior"> 
      <host> 
       <baseAddresses> 
        <add baseAddress="http://localhost:900/mex/"/> 
        <add baseAddress="net.tcp://localhost:9000/" /> 
       </baseAddresses> 
      </host> 
      <endpoint bindingConfiguration="NetTcpBinding_ImageResizerServiceContract" binding="netTcpBinding" contract="LogoResizer.WCF.ServiceContracts.IImageResizerService" /> 
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
     </service> 
    </services> 
</system.serviceModel> 

注意bindingConfiguration =“NetTcpBinding_ImageResizerServiceContract”已添加到netTcp端点。我的应用程序现在可以处理较大的图像甜。

6

请在绑定中添加<readerQuotas>

这是上传和下载byte []时的主要问题,它解决了我的问题。

<basicHttpBinding> 
    <binding name="ServicesBinding" transferMode="Streamed" maxBufferSize="200000000" 
     maxReceivedMessageSize="200000000" messageEncoding="Text" 
     receiveTimeout="00:10:00"> 
     <readerQuotas maxDepth="2147483647" 
      maxStringContentLength="2147483647" 
      maxArrayLength="2147483647" 
      maxBytesPerRead="2147483647" 
      maxNameTableCharCount="2147483647" /> 
    </binding> 
</basicHttpBinding> 
2

我利用了Microsoft SDK SvcConfigEditor。如果你使用Visual Studio(它有自己的版本),你有这个。它也是免费下载的。

在硬盘驱动器(同时检查程序文件和程序文件(x86)):

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\SvcConfigEditor.exe

C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\NETFX 4.0 Tools\SvcConfigEditor.exe

如果你有微软SDK,你用的什么版本将依赖于.NET的是什么版本的多个安装你正在开发下。该工具会抛出一个错误,让你知道你试图打开错误版本下的.dll文件。

要使用该工具,请指向您的服务的.dll文件并让该工具完成繁重工作。如果您的服务与服务交谈(代理服务),这特别有用。另外,请记住,您可能需要为您的客户端(在应用程序)和服务器配置(在web服务)配置设置。

我错过了服务器端端点上的配置。我不得不做两件事情:

  1. 将端点上我的服务器端配置,使用SvcConfigEditor
  2. 记住设置的MaxArrayLength在SvcConfigEditor工具

还配置,ASP.NET是因此您可能会尝试简化您的配置绑定并将其关闭:

<serviceHostingEnvironment multipleSiteBindingsEnabled="false" /> 
-2

它的工作原来显示net.tcp:// mys的引用ervice.com/Ac_Service.svc/mex当浏览wcf服务,但现在它的 http://myservice.com/Ac_Service.svc?wsdl

它将在未来的工作,没有任何问题。