1

I am trying to consume a web service from a third party. Whenever the message that I send to the server passes a certain size, I am getting the following exception:

Unhandled Exception: System.ServiceModel.CommunicationException: An error occurred while making the HTTP request to https://host/path. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server.
---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send.
---> System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.
---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

I am pretty sure that the first message regarding HTTP.SYS is incorrect because it works if I decrease the message size.

This is the code of a successful call:

var request = new GreetingUploadRequest
                {
                    msisdn = "12345678900",
                    personalGreetingVoiceData = File
                        .ReadAllBytes(@"d:\Temp\sample.wav")
                        .Take(48876)
                        .ToArray()
                };
var response = service.GreetingUpload(request);

And this is the code of an unsuccessful call:

var request = new GreetingUploadRequest
                {
                    msisdn = "12345678900",
                    personalGreetingVoiceData = File
                        .ReadAllBytes(@"d:\Temp\sample.wav")
                        .Take(48877)
                        .ToArray()
                };
var response = service.GreetingUpload(request);

As you can see, the only difference is in the Take - it is sending one byte more.
I have increased every setting I could think of, but to no avail:

<system.web>
    <httpRuntime maxRequestLength="2147483647" />
</system.web>
<system.serviceModel>  
    <bindings>
        <basicHttpsBinding>
          <binding name="VmsGreetingUploadWSSoapBinding" closeTimeout="10:01:00"
                   openTimeout="10:01:00" receiveTimeout="10:10:00" sendTimeout="10:01:00"
                   allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                   maxBufferSize="2147483647" maxBufferPoolSize="5147483647" maxReceivedMessageSize="2147483647"
                   messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                   useDefaultWebProxy="true">
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                          maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
            <security>
              <transport clientCredentialType="Basic" proxyCredentialType="None" realm="" />
            </security>
          </binding>
        </basicHttpsBinding>
    </bindings>
  <behaviors>
    <endpointBehaviors>
      <behavior name="endPoint">
        <dataContractSerializer maxItemsInObjectGraph="2147483647" />
      </behavior>
    </endpointBehaviors>
  </behaviors>
    <client>
        <endpoint address="https://host/path"
            binding="basicHttpsBinding" bindingConfiguration="VmsGreetingUploadWSSoapBinding"
            contract="ServiceReference1.VmsGreetingUploadWS" name="VmsGreetingUploadWS" />
    </client>
</system.serviceModel>

Important: The server seems to be configured correctly, because I can send the full data from a SoapUI project!

What setting am I missing? How can I further troubleshoot this?

However, the message size can't be the only problem, because if I route the request through Fiddler 4 - and allow it to decrypt HTTPS traffic - it works even with big messages!

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
  • First thing to do in such cases is configure WCF logging and look at those logs I think. – Evk Jun 27 '17 at 07:20
  • What logging exactly do you mean? – Daniel Hilgarth Jun 27 '17 at 07:20
  • This logging: https://learn.microsoft.com/en-us/dotnet/framework/wcf/diagnostics/configuring-message-logging – Evk Jun 27 '17 at 07:21
  • This just logs the same thing I am seeing in the exception that is thrown – Daniel Hilgarth Jun 27 '17 at 07:29
  • Usually there is much more info in such kind of logs, especially on verbose level. Do you log on both client and server (I see now you talk about trird party so you can only log on client). – Evk Jun 27 '17 at 07:31
  • Yes, there is much more. But not related to the problem :-( I don't have access to the server and I think it isn't even implemented in C# – Daniel Hilgarth Jun 27 '17 at 07:34
  • Maybe you can compare request made from SoapUI and request made by your application in fiddler? Very strange by the way that it works when routing through fiddler, because it should not modify request\response. You can also look at windows event log (system events) and look if there are SChannel errors there (related to ssl). – Evk Jun 27 '17 at 07:49
  • No error in the event log. I find it strange too, that Fiddler changes the outcome. However, I think I found the problem, sort of: The server wants the byte array to be base64 and the URL encoded. It looks like WCF doesn't perform the URL encoding. Why it is working through fiddler, I still don't know. Building the SOAP request by hand using `HttpClient` allows me to successfully transmit the data. And for me, that's the solution I am going with, as that API is only that single action – Daniel Hilgarth Jun 27 '17 at 08:01
  • Possible duplicate of [WCF Error "This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case"](https://stackoverflow.com/questions/2013880/wcf-error-this-could-be-due-to-the-fact-that-the-server-certificate-is-not-conf) – kenorb Oct 02 '18 at 16:32

0 Answers0