The .net clients - Channel Factory & HttpClient behaving differently for "Expect100Continue" header

Jenus M 6 Reputation points
2022-11-25T18:50:26.423+00:00

I have WCF service hosted in a Custom Microsoft Web Server. I have tried to consume the services with TLS 1.3 and with Expect:100-Continue header by two .net provided clients.

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13;

The above statement is common for both clients, because the server is supporting "Expect:100-Continue header" and TLS 1.3. The client I' running in a Windows 11 PC, so client also supporting TLS 1.3.

Client 1: :

HttpsTransportBindingElement myBinding = new HttpsTransportBindingElement();  
        myBinding.AuthenticationScheme = System.Net.AuthenticationSchemes.Basic;  
        TextMessageEncodingBindingElement textMessageEncoding = new TextMessageEncodingBindingElement();  
        textMessageEncoding.MessageVersion = MessageVersion.Soap12WSAddressingAugust2004;  

        CustomBinding binding = new CustomBinding(textMessageEncoding, myBinding);             
        EndpointAddress myEndpoint = new EndpointAddress("https://ip:port/MyService");  

        ChannelFactory<IMyService> myChannelFactory = new ChannelFactory<IMyService>(binding, myEndpoint);  

        myChannelFactory.Credentials.UserName.UserName = "admin";  
        myChannelFactory.Credentials.UserName.Password = "";  


        var wcfClient1 = myChannelFactory.CreateChannel();              
        var myResponse = wcfClient1.MyMethod();  

Client 2 :

HttpClient client = new HttpClient();    
string body = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/"><s:Body>;.....";  
StringContent content = new StringContent(body, Encoding.UTF8, "text/xml");  
var response = await client.PostAsync("https://ip:port/MyService", content);  
         

My problem is - When with Client 1, In the server, the request is coming only with headers (no body) and the body is coming later. But with Client 2, from the first time itself the Header and Body is coming along with request.

Why this two .net clients behaving differently for "Expect100Continue" header ? Which client is honoring the "Expect100Continue" header ?

With TLS 1.2 option both client behave same, the first time itself request have both header and body.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,371 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,238 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,119 questions
ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
294 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 55,686 Reputation points
    2022-11-27T18:11:38.53+00:00

    The header is a client header, not server. The server should support it correctly. As it slows down performance, this header is seldom used anymore and is not recommended. You don’t specify which framework version you are using for HttpClient, but core versions do not support the header on windows (because the lower layers don’t)