0

I tried to use the same service as @Misiu like in: Custom MessageEncoder add attributes to message without modifying structure

I know that post has 3 years but I hope someone knows the answer.
I'm facing the same problem.

System.ServiceModel.CommunicationException: An error occurred while making the HTTP request to https://dz3.swd.zbp.pl/broker3/services/QueryDz. 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 read data from 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

mskuratowski
  • 4,014
  • 15
  • 58
  • 109

1 Answers1

0

I don’t know the ins and outs of the issue. The above error mainly indicates that the service certificate is not properly configured when we make the service work over HTTPS, as the error mentioned. In order to make WCF service work over HTTPS, we should add a service endpoint with transport security mode.

    <services>
      <service name="WcfService3.Service1">
        <endpoint address="" binding="webHttpBinding" bindingConfiguration="mybinding" contract="WcfService3.IService1" behaviorConfiguration="mybeh"></endpoint>
      </service>
    </services>
    <bindings>
      <webHttpBinding>
        <binding name="mybinding">
          <security mode="Transport">
            <transport clientCredentialType="None"></transport>
          </security>
        </binding>
      </webHttpBinding>
</bindings>

Subsequently, if the WCF project is hosted in IIS, we should add an https binding and bind a certificate in the IIS site binding module.
enter image description here
If the service is self-hosted, we could bind a certificate to a specific port by using the following command.

netsh http add sslcert ipport=0.0.0.0:8000 certhash=0000000000003ed9cd0c315bbb6dc1c08da5e6 appid={00112233-4455-6677-8899-AABBCCDDEEFF}

Please refer to the below documentation.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-configure-a-port-with-an-ssl-certificate
Feel free to let me know if there is anything I can help with.

Abraham Qian
  • 7,117
  • 1
  • 8
  • 22