Click here to Skip to main content
14,738,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All.
I hate posting questions (hope this one came out OK). Always trying to find the answers in forums first. This time around I'm stumped. I know there are a million and 2 questions asked about this subject and still I cant find my answer.

The Problem: (I'm new to WCF)
I'm trying to send a file to the server from the client. The usual 45kb works but none bigger as the 400 bad request pops up and ruins my hair style. It looks like my setup is a bit different from what other people are using as I am doing self hosting. As a result I do not have a web.config file, or... should I have one? Anyway I have mutilated this code with a broken keyboard (hair in the keys) trying to figure out what's wrong with it by deleting and plugging in stuffs from a million and 2 forums. I need a second pair of eyes to look at this and tell me where I'm going wrong. Any and every suggestion will be greatly appreciated.

The setup:
I am running a server side and a client in DEV on the local machine. C#.net 3.5.
WCF is self hosted in console app.

Server app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <system.web>
    <compilation debug="true" />
    <httpRuntime maxRequestLength="67108864"/>
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="WCFRemote.Service1Behavior" name="WCFRemote.Interface">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding" contract="WCFRemote.IInterface">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/WCFRemote/Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
          <binding name="basicHttpBinding"

              maxReceivedMessageSize="67108864"

              maxBufferSize="67108864" transferMode="Streamed" >

          <readerQuotas maxDepth="67108864" maxStringContentLength="67108864"

               maxArrayLength="67108864" maxBytesPerRead="67108864"

               maxNameTableCharCount="67108864"/>
        </binding>
       </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WCFRemote.Service1Behavior">
          <!-- 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>
  </system.serviceModel>

</configuration>


Client app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IInterface" closeTimeout="04:01:00"

                    openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00"

                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"

                    maxBufferSize="67108864" maxBufferPoolSize="67108864" maxReceivedMessageSize="67108864"

                    messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed"

                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="67108864" maxArrayLength="67108864"

                        maxBytesPerRead="67108864" maxNameTableCharCount="67108864" />
                  <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"

                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
          <endpoint address="http://jay-vm7dev:8080/service/basic" binding="basicHttpBinding"

                bindingConfiguration="BasicHttpBinding_IInterface" contract="ServiceReference1.IInterface"

                name="BasicHttpBinding_IInterface"/>
        </client>
    </system.serviceModel>
</configuration>


I would have ask my colleges to have a look but since I'm the only developer in my company... Help...

Thanx in Advance from the guy looking like a cancer patient. KCCO!
Posted
v2

1 solution

I googled about it & found this. please check if this helps you.



You are very close to the solution, but you are mixing the bindings. Your service is using basicHttpBinding, but you have set the size limits on webHttpBinding.

Therefore: In your web.config for the service, replace webHttpBinding with basicHttpBinding and this will work, like this:
<basichttpbinding>
   <binding maxbuffersize="64000000" maxreceivedmessagesize="64000000" maxbufferpoolsize="64000000">
     <readerquotas maxdepth="64000000" maxstringcontentlength="64000000" maxarraylength="64000000" maxbytesperread="64000000" />
     <security mode="None" />
   </binding>
 </basichttpbinding>


Increase the timeout time & buffer size at both ends. I have seen 9 to 10 digits size.

Links might help you

http://forums.asp.net/t/1299246.aspx/1[^]

WCF Service returns (400) Bad Request[^]

http://stackoverflow.com/a/784684[^]
   
v4
Comments
The -=!F34R!=- 5-Jul-13 8:22am
   
@Sushil Mate. Thank you for your quick response. I cant see the link you posted. Maybe I'm missing something here, but I cant seem to find where I referenced webHttpBinding either. Am I just being an Idiot? Can you please point me to the snipped of code I need to look at?
Sushil Mate 6-Jul-13 11:42am
   
search for this number 67108864 & increase with 9/10 digit number in server/client app.config file.
The -=!F34R!=- 8-Jul-13 2:32am
   
@Sushil Mate. By my calculations these values should be able to work to 64MB and I'm trying to send 500kb. I did increase these values, but still no joy.
Sushil Mate 8-Jul-13 2:38am
   
Can you send the file which is lesser than 500kb? did you increase timeout?
Sushil Mate 8-Jul-13 2:42am
   
check the updated solution, I have added some links to it.
The -=!F34R!=- 8-Jul-13 6:59am
   
I can Send a file that is less than 45kb I'll check out the posted links and let you know how it turned out. Thank you for your ongoing support.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900