Bad response (400) with a WCF streaming service configured programmatically

this if my first attempt at using streaming for WCF, and I am struggling with the dreadful "The remote server returned an unexpected response: (400) Bad Request" response.

The trace viewer says that this is a System.ServiceModel.ProtocolException with message "There is a problem with the XML that was received from the network. See inner exception for more details." The inner exception type says "The body of the message cannot be read because it is empty."

Leaving everything else equal, if I switch to buffered mode on the client side, I am able to debug into the server code!

For some reason, I have to configure my service programmatically, as follows:

    public IUniverseFileService OpenProxy(string serviceUrl)

        var binding = new BasicHttpBinding();
        binding.Name = "basicHttpStream";
        binding.MaxReceivedMessageSize = 1000000;
        binding.TransferMode = TransferMode.Streamed;

        var channelFactory = 
           new ChannelFactory<localhost.IUniverseFileService>(
              new EndpointAddress(serviceUrl));

        return channelFactory.CreateChannel();

While the server is configured as follows:

    <!-- BEHAVIORS -->
        <behavior name="serviceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="true"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    <!-- SERVICES -->
      <service behaviorConfiguration="serviceBehavior" name="Org.Acme.UniverseFileService">
        <endpoint address="" 
                  contract="Org.Acme.RemoteCommand.Service.IUniverseFileService" /> 
        <endpoint address="mex" 
                  bindingConfiguration="" name="mexStream" 
    <!-- BINDINGS -->
        <binding name="httpLargeMessageStream" 

I appreciate your help!



Everything started to work when I changed the transfer mode from Streamed to StreamedResponse as follows:

binding.TransferMode = TransferMode.StreamedResponse;

Still I don't understand why this works and Streamed does not, and why I am able to both send and receive a file stream from the server.

Streaming mode is not supported by ASP.NET development server. You need to deploy the service to IIS (or a WCF Service Application) to use Streaming mode.

Try to add messageEncoding="Mtom" in bining tag.

Need Your Help

CSS3 animation for rotation of an image, with parameters controlled by javascript

javascript html css css3 rotation

I would like to continuously rotate an image efficiently -- it must work smoothly on mobile browsers. I am currently using CSS3 animation. I would like to be able to control the CSS functionality...

Tkinter with Python 3.3 : Change colour of button on click

python python-3.x tkinter

So I have been playing with tkinter to try add a gui to a lift simulator project I have written for university. It is not really needed, but I would like to add it.