troubleshooting Question

WCF Bad Request

Avatar of Curtis Long
Curtis LongFlag for United States of America asked on
C#HTTP ProtocolWCF
5 Comments1 Solution1437 ViewsLast Modified:
I am working on an image upload service using a WCF Service and .NET 4.0. I can have my client upload small files, like a txt file that was only 14 bytes. However, when I try to upload an image file (860k) I get this exception:
"The remote server returned an unexpected response: (400) Bad Request." I found several places that mentioned making the max file size bigger in my app.config file. I changed it to allow about 2gb just to be sure I wouldn't go over.

<?xml version="1.0" encoding="utf-8" ?>
                <binding name="BasicHttpBinding_IUploadService" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="200000000" maxBufferPoolSize="200000000" maxReceivedMessageSize="200000000"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    <readerQuotas maxDepth="32" maxStringContentLength="200000000" maxArrayLength="200000000"
                        maxBytesPerRead="200000000" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
            <endpoint address="http://localhost:51353/UploadService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IUploadService"
                contract="UploadService.IUploadService" name="BasicHttpBinding_IUploadService" />

It didn't make sense to me to have to make those changes on the client side to fix a server response, so I added this to my web.config file on the service side.

<httpRuntime maxRequestLength="200000000" />

my entire web.config

<?xml version="1.0"?>

    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime maxRequestLength="200000000" />
          <!-- 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"/>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <modules runAllManagedModulesForAllRequests="true"/>

I have been battling with this for the last couple hours, so any help is greatly appreciated.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros