buildtehawesome
buildtehawesome

Reputation: 21

Streaming WCF - 400 Bad Request

I have been circling around setting up a Streaming service for the last couple days and everytime I come back to the task I keep hitting the same wall of 400 Bad Request. I have searched a number of posts here and out on the web and it seems like this is a frequent issue but each situation is different. Below is the current state of my bindings setup - I feel like this has to be something small I am overlooking.

Information from WCF profiler:

This leads me to believe that whatever I have set up is not being applied to the service and, hence, throw the Bad Request error because it is using the ~64kb default which my stream exceeds.

      <!-- Services Config -->
        <system.web>
        <httpRuntime maxRequestLength="2097150" executionTimeout="7200"/>
        <compilation debug="true" targetFramework="4.0" />    
        </system.web>
    <system.serviceModel>
    <bindings>
      <basicHttpBinding>        
          <binding name="StreamingService"  maxReceivedMessageSize="2147483647"  maxBufferSize="2147483647" transferMode="Streamed" >
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
            <security mode="None">
            </security>
          </binding>        
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="StreamingService" behaviorConfiguration="StreamingServiceBehavior">
          <endpoint address="http://localhost:50577/StreamingContent.svc"
         binding="basicHttpBinding" bindingConfiguration="StreamingService"
         contract="IStreamingContent" name="BasicHttpBinding_IStreamingContent" />
      </service>
    </services>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

       <!-- Web Server Config -->
        <bindings>
        <basicHttpBinding>
  <binding name="BasicHttpBinding_IStreamingContent" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="00:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="128" 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:50577/StreamingService.svc"
             binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IStreamingService"
            contract="StreamingService.IStreamingService" name="BasicHttpBinding_IStreamingService" />
        </client>

Any fresh perspectives would certainly help.

EDIT: I updated the configurations above after taking the advice below but I am still getting the same issue in the profiler where no matching tag is found, only this time I believe my setup is correct..... obviously not because it would work now wouldn't it, eh?

Thoughts?

Upvotes: 2

Views: 1172

Answers (2)

granadaCoder
granadaCoder

Reputation: 27874

For future readers.

I got the "No matching tag was found. Default endpoints added."

My xml was fine. (after I spent an hour trying to find malformed xml).

The issue for me was I had changed the namespace of my concrete-service class.

The key is this.

In the .svc file, there is a some markup

<%@ ServiceHost Language="C#" Debug="true" Service="MyCompany.MyNamespace.MyConcreteService" %>

This has to be the FULLY qualified name of the .cs class.

AND

your service model xml has to have the fully qualfied name as well.

  <service name="MyCompany.MyNamespace.MyConcreteService"
           behaviorConfiguration="MyServiceBehavior"
           >

        <!-- 
        Whole bunch of other stuff not shown here
        -->

  </service>

The above would mimic the class

namespace MyCompany.MyNamespace
{
    public class MyConcreteService : IMyService
    {
    }
}

Make sure you have the CORRECT fully qualified name AND they are copied to the .svc file correctly AND the xml correctly.

I got the answer from here:

https://social.msdn.microsoft.com/Forums/vstudio/en-US/3bb9b3ad-8fc4-40a6-9bb8-fb34f9011d39/bad-request-error-when-uploading-file-to-server?forum=wcf

It's possible that the element is not being recognized by WCF. The value of the "name" attribute in the element must be the fully-qualified name of the service class - since you're using IIS to host the service, it needs to be the same value as the "Service" attribute in the @ServiceHost tag in the .svc file.

Upvotes: 0

Maksym Strukov
Maksym Strukov

Reputation: 2689

I think that one of the reasons of your issue is that you configuring an endpoint using <client> section on the server side when in fact you should use <services> section to configure your service endpoint. Please see an example of the server config file for streaming here http://www.c-sharpcorner.com/uploadfile/dhananjaycoder/streaming-in-wcf/

Be really careful with your config files this is where most problems come in WCF

Upvotes: 3

Related Questions