I am writing a POC application which uses Microsoft.ServiceBus.dll 1.0.0.0 (the .NET 3.5 version).

My WCF contract and service look like the following:

[ServiceContract(Name="MyServiceContract", Namespace = "http://mydomain.com/")]
internal interface IServiceContract
{
    [WebInvoke(Method = "POST", UriTemplate = "/DoOperation")]
    [OperationContract]
    Stream RelayRequest(Stream requestBody);
}

[ServiceBehavior(Name = "Service1", Namespace = "http://mydomain.com/Service1/", InstanceContextMode = InstanceContextMode.Single)]
internal class Service1 : IServiceContract
{
    Stream RelayRequest(Stream requestBody)
    {
        var contents = GetJsonResponse();
        var responseStream = new MemoryStream();
        var streamWriter = new StreamWriter(responseStream);
        streamWriter.AutoFlush = true;
        var writer = new JsonTextWriter(streamWriter);
        var serializer = new JsonSerializer();
        serializer.Serialize(responseStream, contents);

        responseStream.Position = 0 // reset the position of the stream so that it's contents will be read from the beginning.

        //Problem Line:
        WebOperationContext.OutgoingResponse.ContentType = "application/json";
        return responseStream;
    }
}

The listening end point is configured to use WebHttpRelayBinding:

  • SecurityMode: Transport
  • TransferMode: Streamed

When I attempt to assign the ContentType of the outgoing response to "application/json" an error doesn't occur but the calling request returns with status code 504 (Gateway Timeout).

If I change the ContentType to "text/javascript" the calling request returns with 200 (OK).

Some things to note:

  • The content-type is not known until run time so it must be dynamically assigned.
  • The contents of the stream is pure - 100% valid - json.
  • The intention for accepting and returning a stream is so we can accep
Edit
Report