Muhammad Faizan Khatri
Muhammad Faizan Khatri

Reputation: 643

Passing bmp file/Image as parameter in wcf service

I am trying to pass a BMP file as a parameter in a WCF Service. I'mm getting an error when the size of the BMP file is 350kb. When I pass a small file of 10-20 kb it runs perfectly.

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

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

I have tried to solve the issue with changing IIS setting following this link: http://blogs.msdn.com/b/jiruss/archive/2007/04/13/http-413-request-entity-too-large-can-t-upload-large-files-using-iis6.aspx but no luck

My Server web.config is

<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>

My Client Web.Config is

<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>

Upvotes: 1

Views: 1125

Answers (1)

&#216;yvind Br&#229;then
&#216;yvind Br&#229;then

Reputation: 60694

On your readerQuotas, try to set maxStringContentLength to 2147483647 as well, and make sure this config is set on both ends.

So both the server and the client need to have these values. It's no help if the client is allowed to send a large file, if the server will reject it anyway.

What is the value of maxArrayLength on the wcf server application

Upvotes: 1

Related Questions