在wcf服务中传递bmp文件/ Image作为参数

时间:2013-02-26 08:25:25

标签: asp.net wcf

我正在尝试将BMP文件作为参数传递给WCF服务。当BMP文件的大小为350kb时,我收到错误。当我传递一个10-20 kb的小文件时,它运行得很好。

The remote server returned an unexpected response: (413) Request Entity Too Large. 

[OperationContract]
byte[] ConvertData(Bitmap bmp);

我尝试通过以下链接更改IIS设置来解决问题:http://blogs.msdn.com/b/jiruss/archive/2007/04/13/http-413-request-entity-too-large-can-t-upload-large-files-using-iis6.aspx但没有运气

我的服务器web.config是

<system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime executionTimeout="240000"/>    
</system.web>

<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="BasicHttpBinding_IService1" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"  hostNameComparisonMode="StrongWildcard" maxReceivedMessageSize="2147483647">
                <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"/>
            </binding>
        </wsHttpBinding>
    </bindings>
    <services>
        <service name="ReDrawImgService.Service1">
            <endpoint address="" binding="wsHttpBinding" bindingConfiguration="" contract="ReDrawImgService.IService1"/>
        </service>
    </services>

    <behaviors>
        <serviceBehaviors>
            <behavior>
                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata httpGetEnabled="true"/>
                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                <serviceDebug includeExceptionDetailInFaults="false"/>

            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

我的客户端Web.Config

<system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime executionTimeout="240000"/>

</system.web>

<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="BasicHttpBinding_IService1" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"  hostNameComparisonMode="StrongWildcard" maxReceivedMessageSize="2147483647">
                <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"/>
            </binding>
        </wsHttpBinding>
    </bindings>
    <services>
        <service name="ReDrawImgService.Service1">
            <endpoint address="" binding="wsHttpBinding" bindingConfiguration="" contract="ReDrawImgService.IService1"/>
        </service>
    </services>

    <client>
        <endpoint address="http://localhost:8012/Service1.svc" binding="wsHttpBinding"
            bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceClient.IService1"
            name="BasicHttpBinding_IService1" />
    </client>
</system.serviceModel>

1 个答案:

答案 0 :(得分:1)

在您的readerQuotas上,尝试将maxStringContentLength设置为2147483647,并确保此配置设置在两端

因此服务器和客户端都需要具有这些值。如果允许客户端发送大文件,如果服务器无论如何都会拒绝它,那就无济于事了。

wcf服务器应用程序上maxArrayLength的值是什么