Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7075505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:11:08+00:00 2026-05-28T06:11:08+00:00

I created a simple RESTful WCF service with a single method for receiving files

  • 0

I created a simple RESTful WCF service with a single method for receiving files and a simple client that uploads a file. The files are simple text files (of course I would like to upload binary files later).

The service will be published for many types of clients so I would like to use an implementation that does not add a service reference.

Am I doing this correctly?

Why do I get a The remote server returned an unexpected response: (400) Bad Request error when I try to upload a simple 1Mb text file?

Edit:
The system works correctly if my file has only a size of 3.7kb. This means I just have to configure the service to accept larger packets. How do I do that?

Service:

    /// <summary>
    /// Data Service REST service that handles data upload.
    /// </summary>
    [AspNetCompatibilityRequirements(
    RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class DataService : Common.Contracts.IDataService
    {
        /// <summary>
        /// Uploads a data file to the server.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <param name="fileContent">Content of the file.</param>
        public string UploadFile(string filename, Stream fileContent)
        {
            return filename;
        }
    }

Service config

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <standardEndpoints>
        <webHttpEndpoint>
            <!--
        Configure the WCF REST service base address 
        via the global.asax.cs file and the default endpoint
        via the attributes on the <standardEndpoint> element below
    -->
            <standardEndpoint name="" helpEnabled="true"
             automaticFormatSelectionEnabled="true"/>
        </webHttpEndpoint>
    </standardEndpoints>
</system.serviceModel>

Contract:

    /// <summary>
    /// Data Service service contract interface.
    /// </summary>
    [ServiceContract]
    public interface IDataService
    {
        /// <summary>
        /// Uploads a data file to the server.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <param name="fileContent">Content of the file.</param>
        [WebInvoke(UriTemplate = "/upload?filename={filename}", 
        Method = "POST", ResponseFormat = WebMessageFormat.Xml)]
        string UploadFile(string filename, System.IO.Stream fileContent);
    }

Client

WebChannelFactory<IDataService> cf = 
new WebChannelFactory<IDataService>(
                  new Uri(Settings.Default.UrlService));
IDataService channel = cf.CreateChannel();
StreamReader fileContent = new StreamReader(path, false);

string response = channel.UploadFile(path, fileContent.BaseStream);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:11:08+00:00Added an answer on May 28, 2026 at 6:11 am

    Can you replace your standardEndpoint element with the below:

    <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxBufferSize="500000" maxReceivedMessageSize="500000" >          
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />          
            </standardEndpoint>
    

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to create and host a simple RESTful WCF Service. The service
I created a simple XML web service using NetBeans 7's RESTful Web Services from
I have a simple resftul wcf service. The .svc file looks like this <%@
I have a simple RESTful web service that print Hello World ! I'm using
I have a RESTful service that I am developing in WCF . I am
I have created a rails application that has a simple RESTful json API. This
How to manually create Friendly URLs? (PHP) So I have created simple php file
I created a simple Converter to concatenate the text of four TextBoxes in my
I have a WCF service hosted that is returning a byte[] of protobuf-net serialized
I created a couple of WCF services. One very robust one that can accept

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.