2

I am new to StackOverflow so forgive me if I get this wrong. I am getting a bad request error when calling a wcf service. The method takes a Byte array as a parameter. It works on small files but not on files that are 80000 bytes in length. I have posted the web config files below.

This is in my web config file

    <system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IFileService" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
      useDefaultWebProxy="true">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
        maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost:4199/FileService.svc" binding="basicHttpBinding"
    bindingConfiguration="BasicHttpBinding_IFileService" contract="ConStringServices.IFileService"
    name="BasicHttpBinding_IFileService" />
</client>

This is in my service web config file

    <system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="basicBinding" maxReceivedMessageSize="2147483647">
                <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
            </binding>              
        </basicHttpBinding>         
    </bindings>
    <services>
        <service behaviorConfiguration="MyServiceBehavior" name="MyService">
            <endpoint  bindingConfiguration="basicBinding" address="" binding="basicHttpBinding" contract="ConStringTest.Services.IFileService">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>             
        </service>          
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="MyServiceBehavior">
                <!-- 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="true"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

Update: This is the method that is called within the service. Like I said, it works with small files.

    public Boolean UploadFile(Byte[] file, string filename)
    {
        FileStream stream = new FileStream("C:\\Temp\\" + filename, FileMode.Create, FileAccess.ReadWrite);
        stream.Write(file, 0, file.Length);
        stream.Close();

        Console.WriteLine(file.Length);
        return true;
    }

What am I doing wrong? Any help would be greatly appreciated. Update: I have amended the service config file as above but still no joy. Update: It is fixed. I just had to make the service name the Fully Qualified Name with namespace. ie. ConStringTest.Services.FileService

3
  • your bindings look ok, ie you have increased the size of the necessary attributes (Eg maxStringContentLength) - could you post some code of what your service does ? perhaps its not config related Commented Dec 5, 2013 at 22:02
  • Thanks for taking the time to have a look. I have now included the method that is being called. I am sure it is config related because it works on small files. I have tested it with 8kb files and it works fine. Commented Dec 6, 2013 at 17:57
  • what does the stack trace say? anything useful? Commented Dec 6, 2013 at 17:59

1 Answer 1

1

The problem is with the config where you are putting the name. This is not an arbritary name but rather the name of the service class file. If its wrong the config will not be applied and will use the default config. Change MyService to be the fully qualified name of the service class..

<service behaviorConfiguration="MyServiceBehavior" name="ConStringTest.Services.FileService">
    <endpoint  bindingConfiguration="basicBinding" address="" binding="basicHttpBinding" contract="ConStringTest.Services.IFileService">
        <identity>
            <dns value="localhost" />
        </identity>
    </endpoint>             
</service> 
Sign up to request clarification or add additional context in comments.

2 Comments

I have just done that and it works. Thank you very much for your answer and for taking the time to look at the problem. I am new to SO. How do I mark your answer as correct?
There should be a checkmark below the voting widget, click it

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.