WCF Content-Length HTTP header on outbound message

前端 未结 3 679
悲哀的现实
悲哀的现实 2020-12-19 20:57

I\'m in a tough situation in which a Java web service endpoint hosted on an IBM HTTP Server (IHS) requires a Content-Length header, although it supposedly conforms to HTTP/1

相关标签:
3条回答
  • 2020-12-19 21:29

    I am not currently able to actually try to run the code to see what happens but something like

    WCFClient client = new WCFClient();
    using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))    
    {     
        HttpRequestMessageProperty req = new HttpRequestMessageProperty();            
        req.Headers.Add("Content-Length", "YOUR CONTENT LENGTH HERE");      
        OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = req;      
    }
    

    see http://msdn.microsoft.com/en-us/library/aa395196.aspx for more information on how you can use the OperationContextScope object to include additional headers.

    update: I do have to say I find this a strange issue. I wonder why the content length isn't being set. I wouldn't be surprissed if your actual problem is somewhere else.

    0 讨论(0)
  • 2020-12-19 21:36

    transferMode=StreamedResponse in the app.config helped me too for an issue similar to yours. I had a WCF architecture for Sync Framework and Squid proxy 3.1.20 didn't like the Streamed transferMode Many thanks !

    0 讨论(0)
  • 2020-12-19 21:41

    Figured it out. Setting the binding to use transferMode="Streamed" was causing a Transfer-Encoding: chunked. We needed streamed transfers due to very large responses from the web service, so I was able to go with:

    Bad:

    transferMode="Streamed"
    

    Good:

    transferMode="StreamedResponse"
    

    Changing the binding to this solved the problem:

    <basicHttpBinding>
        <binding name="MyBinding" closeTimeout="00:30:00" openTimeout="00:30:00"
          receiveTimeout="00:30:00" sendTimeout="00:30:00" allowCookies="false"
          bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="16777216"
          messageEncoding="Text" textEncoding="utf-8" transferMode="StreamedResponse"
          useDefaultWebProxy="false">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="65536"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None" />
        </binding>
      </basicHttpBinding>
    
    0 讨论(0)
提交回复
热议问题