C# 向服务发出HTTPS请求时出错?服务上没有痕迹?

C# 向服务发出HTTPS请求时出错?服务上没有痕迹?,c#,web-services,wcf,ssl,C#,Web Services,Wcf,Ssl,我有一个包含两个WCF服务的解决方案,在一个窗口服务中自托管,一个用于常规http,一个用于https。客户端可以连接到http服务,但当连接到https服务时,我得到: 向发出HTTP请求时出错 . 这可能是由于 服务器证书的配置不正确 HTTPS案例中的HTTP.SYS。这也可能是由于 客户端和服务器之间的安全绑定 我已经检查了网址和它的正确性 首先,我在客户端激活WCF跟踪,我可以看到这一点 连接时接收字节 System.ServiceModel.CommunicationExceptio

我有一个包含两个WCF服务的解决方案,在一个窗口服务中自托管,一个用于常规http,一个用于https。客户端可以连接到http服务,但当连接到https服务时,我得到:

向发出HTTP请求时出错 . 这可能是由于 服务器证书的配置不正确 HTTPS案例中的HTTP.SYS。这也可能是由于 客户端和服务器之间的安全绑定

我已经检查了网址和它的正确性

首先,我在客户端激活WCF跟踪,我可以看到这一点

连接时接收字节

System.ServiceModel.CommunicationException,System.ServiceModel,版本=4.0.0.0,区域性=中性,PublicKeyToken=b77a5c561934e089
向发出HTTP请求时出错https://192.168.130.29:44390/MyAppService/Sll. 这可能是因为在HTTPS情况下,服务器证书未正确配置为HTTP.SYS。这也可能是由于客户端和服务器之间的安全绑定不匹配造成的。
位于System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException WebException、HttpWebRequest请求、HttpBortreason abortReason)
位于System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelAsyncRequest.CompleteTResponse(IAsyncResult结果)
位于System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelAsyncRequest.OnGetResponse(IAsyncResult结果)
在System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult结果)中
在System.Net.LazyAsyncResult.Complete(IntPtr userToken)中
在System.Net.ContextawarerResult.CompleteCallback(对象状态)中
位于System.Threading.ExecutionContext.RunInternal(ExecutionContext ExecutionContext、ContextCallback回调、对象状态、布尔值preserveSyncCtx)
在System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态,布尔保存SyncCTX)
在System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态)
在System.Net.ContextAwareResult.Complete(IntPtr userToken)
在System.Net.LazyAsyncResult.ProtectedInvokeCallback(对象结果,IntPtr userToken)
在System.Net.HttpWebRequest.SetResponse中(异常E)
在System.Net.HttpWebRequest.CheckWriteSiderResponseProcessing()中
在System.Net.ConnectStream.ProcessWriteCallDone处(ConnectionReturnResult)
在System.Net.HttpWebRequest.WriteCallDone(ConnectStream、ConnectionReturnResult)
在System.Net.ConnectStream.CallDone(ConnectionReturnResult)上
在System.Net.ConnectStream.IOError(异常,布尔值willThrow)
位于System.Net.ConnectStream.HandleWriteHeadersException(异常e,WebExceptionStatus错误)
位于System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
在System.Net.LazyAsyncResult.Complete(IntPtr userToken)中
在System.Net.LazyAsyncResult.ProtectedInvokeCallback(对象结果,IntPtr userToken)
在System.Net.TlsStream.ResumeIOWorker处(对象结果)
在System.Net.TlsStream.WakeupPendingIO(IAsyncResult ar)上
在System.Net.LazyAsyncResult.Complete(IntPtr userToken)中
在System.Net.LazyAsyncResult.ProtectedInvokeCallback(对象结果,IntPtr userToken)
位于System.Net.FixedSizeReader.ReadCallback(IAsyncResult transportResult)
在System.Net.LazyAsyncResult.Complete(IntPtr userToken)中
在System.Net.ContextawarerResult.CompleteCallback(对象状态)中
位于System.Threading.ExecutionContext.RunInternal(ExecutionContext ExecutionContext、ContextCallback回调、对象状态、布尔值preserveSyncCtx)
在System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态,布尔保存SyncCTX)
在System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态)
在System.Net.ContextAwareResult.Complete(IntPtr userToken)
在System.Net.LazyAsyncResult.ProtectedInvokeCallback(对象结果,IntPtr userToken)
位于System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32错误代码,UInt32个字节,NativeOverlapped*NativeOverlapped)
在System.Threading.\u IOCompletionCallback.PerformiCompletionCallback(UInt32错误代码,UInt32个字节,本机重叠*pOVERLAP)
System.ServiceModel.CommunicationException:向发出HTTP请求时出错https://192.168.130.29:44390/MyAppService/Sll. 这可能是因为在HTTPS情况下,服务器证书未正确配置为HTTP.SYS。这也可能是由于客户端和服务器之间的安全绑定不匹配造成的。--System.Net.WebException:基础连接已关闭:发送时发生意外错误。--System.IO.IOException:无法从传输连接读取数据:远程主机强制关闭了现有连接。--System.Net.Sockets.SocketException:远程主机强制关闭了现有连接
位于System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
位于System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
---内部异常堆栈跟踪的结束---
在System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)中
在System.Net.PooledStream.EndWrite(IAsyncResult asyncResult)中
位于System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
---内部异常堆栈跟踪的结束---
位于System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
位于System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelAsyncRequest.CompleteTResponse(IAsyncResult结果)
---内部异常堆栈跟踪的结束---
System.Net.WebException,系统,版本=4.0.0.0,区域性=中性,PublicKeyToken=b77a5c561934e089
基础连接已关闭:se上发生意外错误
<ExceptionType>System.ServiceModel.CommunicationException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>An error occurred while making the HTTP request to https://192.168.130.29:44390/MyAppService/Sll. 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.</Message>
<StackTrace>
at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelAsyncRequest.OnGetResponse(IAsyncResult result)
at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.ContextAwareResult.CompleteCallback(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.HttpWebRequest.SetResponse(Exception E)
at System.Net.HttpWebRequest.CheckWriteSideResponseProcessing()
at System.Net.ConnectStream.ProcessWriteCallDone(ConnectionReturnResult returnResult)
at System.Net.HttpWebRequest.WriteCallDone(ConnectStream stream, ConnectionReturnResult returnResult)
at System.Net.ConnectStream.CallDone(ConnectionReturnResult returnResult)
at System.Net.ConnectStream.IOError(Exception exception, Boolean willThrow)
at System.Net.ConnectStream.HandleWriteHeadersException(Exception e, WebExceptionStatus error)
at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.TlsStream.ResumeIOWorker(Object result)
at System.Net.TlsStream.WakeupPendingIO(IAsyncResult ar)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.FixedSizeReader.ReadCallback(IAsyncResult transportResult)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.ContextAwareResult.CompleteCallback(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
</StackTrace>
<ExceptionString>System.ServiceModel.CommunicationException: An error occurred while making the HTTP request to https://192.168.130.29:44390/MyAppService/Sll. 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. ---&gt; System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---&gt; System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---&gt; System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
   at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
   --- End of inner exception stack trace ---
   at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
   at System.Net.PooledStream.EndWrite(IAsyncResult asyncResult)
   at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
   --- End of inner exception stack trace ---</ExceptionString>
<InnerException>
<ExceptionType>System.Net.WebException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>The underlying connection was closed: An unexpected error occurred on a send.</Message>
<StackTrace>
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
</StackTrace>
<ExceptionString>System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---&gt; System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---&gt; System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
   at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
   --- End of inner exception stack trace ---
   at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
   at System.Net.PooledStream.EndWrite(IAsyncResult asyncResult)
   at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)</ExceptionString>
<InnerException>
<ExceptionType>System.IO.IOException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.</Message>
<StackTrace>
at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
at System.Net.PooledStream.EndWrite(IAsyncResult asyncResult)
at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
</StackTrace>
<ExceptionString>System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---&gt; System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
   at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
   --- End of inner exception stack trace ---
   at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
   at System.Net.PooledStream.EndWrite(IAsyncResult asyncResult)
   at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)</ExceptionString>
<InnerException>
<ExceptionType>System.Net.Sockets.SocketException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>An existing connection was forcibly closed by the remote host</Message>
<StackTrace>
at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
</StackTrace>
<ExceptionString>System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
   at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)</ExceptionString>
<NativeErrorCode>2746</NativeErrorCode>
</InnerException>
</InnerException>
</InnerException>
private async Task<ChannelFactory<T>> CreateChannelFactory(LoginTypeBase loginType, MyAppToken token)
{
    var service = await _ConsulService.GetServiceBlocking(loginType.MyAppServicesToUse, forceRefresh: true, token: new CancellationTokenSource(TimeSpan.FromSeconds(30)).Token);

    if (service == null)
        throw new MyAppServiceCommunicationException();

    var uri = loginType.GetMyAppClientServiceURL(service.Address, service.Port);

    var header = AddressHeader.CreateAddressHeader(nameof(MyAppToken), nameof(MyAppToken), token);
    var endpointAddress = new EndpointAddress(uri, header);

    ServiceEndpoint serviceEndpoint = null;
    if (loginType.LoginType == LoginType.SmartCard || loginType.LoginType == LoginType.UsernamePasswordSecure)
    {
        var binding = new NetHttpsBinding("netHttpsBinding");
        binding.Security.Mode = BasicHttpsSecurityMode.Transport;
        binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;

        serviceEndpoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(T)), binding, endpointAddress);
    }
    else
    {
        var binding = new NetHttpBinding("netHttpBinding");
        serviceEndpoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(T)), binding, endpointAddress);
    }

    serviceEndpoint.EndpointBehaviors.Add(new ProtoEndpointBehavior());
    serviceEndpoint.EndpointBehaviors.Add(new CustomMessageInspectorBehavior());


    var v = new ChannelFactory<T>(serviceEndpoint);
    return v;
}