TimeSpan duration = new TimeSpan(0,1,0); SomePortTypeclient someclient = new SomePortTypeclient("https://endpointURL",duration,"username","password"); var respOnse= someclient.someMethod(someParameter).Result;
更新:似乎证书没有使用正确的私钥签名。我重新导入了证书,错误消失了,但是现在我收到了一个新错误,提示“ A security error was encountered when verifying the message”。我环顾四周,看来这通常是由客户端/服务器之间的时间差异引起的。我也不知道如何解决此问题,因此不胜感激。
更新:我启用了WCF跟踪,这是该异常的堆栈跟踪:
131075302LAPTOP-U7FDFsnIhttps://docs.microsoft.com/dotnet/framework/wcf/diagnostics/tracing/System-ServiceModel-Diagnostics-ThrowingExceptionThrowing an exception.ConsoleApp1.exeSystem.ServiceModel.Security.SecurityNegotiationException,System.ServiceModel,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089Could not establish secure channel for SSL/TLS with authority 'URI'. 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,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.Security.SslState.FinishHandshake(Exception e,AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ReadFrameCallback(AsyncProtocolRequest asyncRequest) at System.Net.AsyncProtocolRequest.CompleteRequest(Int32 result) at System.Net.FixedSizeReader.CheckCompletionBeforeNextRead(Int32 bytes) 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,IntPtr userToken) at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode,UInt32 numBytes,NativeOverlapped* nativeOverlapped) at System.Threading._IOCompletionCallback.PerformioCompletionCallback(UInt32 errorCode,NativeOverlapped* pOVERLAP) System.ServiceModel.Security.SecurityNegotiationException: Could not establish secure channel for SSL/TLS with authority 'URI'. ---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel. at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result) --- End of inner exception stack trace ---System.Net.WebException,System,PublicKeyToken=b77a5c561934e089The request was aborted: Could not create SSL/TLS secure channel. at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel. at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)