0

I am getting (400) Bad Request returned when I call a WCF service via SOAP where the method takes a single parameter of type Stream and the transferMode=Streamed.

I get this exception only when I publish the service using the RouteTable class:

RouteTable.Routes.Add(new ServiceRoute("ping", new ServiceHostFactory(), typeof(PingService)));

If I create a ServiceHost myself then I can call the service with no problems:

host = new ServiceHost(typeof(PingService));
host.Open();

Here is an example of the Service contract:

[ServiceContract]
public interface IPing
{
   [OperationContract]
   Stream Ping(Stream stream);
}

Here is the Web.config:

<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
  <system.serviceModel>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>

    <services>
      <service name="SoapStreamedWebServiceTest.PingService" behaviorConfiguration="md">
        <endpoint address="" binding="basicHttpBinding" contract="SoapStreamedWebServiceTest.IPing"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="md">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <bindings>
      <basicHttpBinding>
        <binding name="stm" transferMode="Streamed"/>
      </basicHttpBinding>
    </bindings>

  </system.serviceModel>
</configuration>

This is only a problem if I create a SOAP service using ServiceHostFactory and basicHttpBinding. If I create a REST service using WebServiceFactory and webHttpBinding then it works fine. However I need to publish both a REST and SOAP endpoint for the same service.

This is also only a problem if the transferMode is Streamed or StreamedRequest, it works for Buffered and StreamedResponse. However I need to allow the consumer to pass me data in a streamed fashion.

If the service is published using the RouteTable then it will return (400) Bad Request when called with transferMode=Streamed without hitting any breakpoint I place within the Ping metod. However if I manually create a Service Host it does hit the breakpoint. I have noticed that the Stream.Lenth property raises an exception when called via SOAP but it does not when called via REST. Could this be anything to do with the problem?

Can anyone shed any light as to why I get (400) Bad Request when calling a SOAP service with transferMode=Streamed when it is published via the RouteTable?

  • Can you try enabling Tracing (http://msdn.microsoft.com/en-us/library/ms733025.aspx) on your service to see why you get a 400 bad request when using Streamed transfer mode – Rajesh Jul 23 '13 at 10:30
  • Also make sure that your stream size is not greater than the default size of 64KB else consider specifying readerQuotas with required settings – Rajesh Jul 23 '13 at 10:32
  • Thank you for your help. It would appear the exception is claiming that "The body of the message cannot be read because it is empty." At the moment I have written a small test app to help me debug the problem I was having with the real web service. I am passing a very small amout of data across in the stream; basically just the text "Hello Stream", just to see if I can get a simple streaming service to work. – Mark Allan Jul 23 '13 at 10:41
  • Can you monitor your raw request using Fiddler to make sure that when the call is being made the data is being streamed – Rajesh Jul 23 '13 at 10:44
  • Also make sure that your client config has the transfermode set to streamed – Rajesh Jul 23 '13 at 10:54
  • The client config is definately set to streamed. If I set this to Buffered or StreamedResponse then the call will succeed. If it is set to Streamed or StreamedRequest I get (400) Bad Request. – Mark Allan Jul 23 '13 at 10:59
  • POST http://192.168.1.82:8000/ping HTTP/1.1 Content-Type: text/xml; charset=utf-8 VsDebuggerCausalityData: uIDPo3XFnEBCkVdNny6+GsMnmPMAAAAAUStc3TCh/kWr62RsLx2/JNQQjU80qH5Oqf52emvE+5wACQAA SOAPAction: "http://tempuri.org/IPing/Ping" Host: 192.168.1.82:8000 Transfer-Encoding: chunked Expect: 100-continue Accept-Encoding: gzip, deflate Proxy-Connection: Keep-Alive X-FCCKV2: Mc5XHHNdoywNfRttLPxicW5epIqV3OZhGQ== AC SGVsbG8gc2VydmljZQ== 0 – Mark Allan Jul 23 '13 at 12:26

0 Answers0