Bad response (400) with WCF streaming service configured programmatically

this is if my first attempt to use streaming for WCF and I am struggling with the terrible "The remote server responded with an unexpected response: (400)" Bad request ".

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

Leaving everything else equal, if I switch to client-side buffered mode, I can debug the server code!

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

public IUniverseFileService OpenProxy(string serviceUrl) { Debug.Assert(!string.IsNullOrEmpty(serviceUrl)); var binding = new BasicHttpBinding(); binding.Name = "basicHttpStream"; binding.MaxReceivedMessageSize = 1000000; binding.TransferMode = TransferMode.Streamed; var channelFactory = new ChannelFactory<localhost.IUniverseFileService>( binding, new EndpointAddress(serviceUrl)); return channelFactory.CreateChannel(); } 

So far, the server is configured as follows:

  <system.serviceModel> <!-- BEHAVIORS --> <behaviors> <serviceBehaviors> <behavior name="serviceBehavior"> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="true"/> <dataContractSerializer maxItemsInObjectGraph="2147483647"/> </behavior> </serviceBehaviors> </behaviors> <!-- SERVICES --> <services> <service behaviorConfiguration="serviceBehavior" name="Org.Acme.UniverseFileService"> <endpoint address="" binding="basicHttpBinding" name="basicHttpStream" bindingConfiguration="httpLargeMessageStream" contract="Org.Acme.RemoteCommand.Service.IUniverseFileService" /> <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" name="mexStream" contract="IMetadataExchange"/> </service> </services> <!-- BINDINGS --> <bindings> <basicHttpBinding> <binding name="httpLargeMessageStream" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" transferMode="Streamed"/> </basicHttpBinding> </bindings> 

I appreciate your help!

Stefano

+4
c # soap wcf streaming
source share
3 answers

It all started when I changed the transfer mode from Streamed to StreamedResponse as follows:

 binding.TransferMode = TransferMode.StreamedResponse; 

However, I do not understand why this works, but Streamed does not, and why I can send and receive a file stream from the server.

+7
source share

Streaming mode is not supported by the ASP.NET development server. To use streaming mode, you need to deploy the service in IIS (or the WCF service application).

+5
source share

Try adding messageEncoding = "Mtom" to the bining tag.

+1
source share

All Articles