我有一个WCF服务(自托管)和客户端,客户端使用客户端证书,该服务使用HTTPS上的服务证书 . 这在计算机上工作正常,但另一个抛出这个:

System.ServiceModel.Security.MessageSecurityException: The HTTP request was forbidden with client authentication scheme 'Anonymous'. ---> System.Net.WebException: The remote server returned an error: (403) Forbidden.
   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
   --- End of inner exception stack trace ---
   at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass7_0`1.<CreateGenericTask>b__0(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Myapp.Client.Main.ServiceManagement.ServiceAgents.General.<GetUserConfigurations>d__5.MoveNext() in C:\Project\Myapp\Produkter\MyappUtveckling\Solution\Myapp.Client.Main\Classes\Service Management\Service Agents\General.cs:line 172

在WCF日志中,我可以看到:

找不到配置评估上下文 .


http://msdn.microsoft.com/sv-SE/library/System.ServiceModel.Channels.HttpChannelUnexpectedResponse.aspx收到错误的HTTP响应Myapp.vshost.exe System.ServiceModel.Security.MessageSecurityException,System.ServiceModel,Version = 4.0 .0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089使用客户端身份验证方案“Anonymous”禁止HTTP请求 . 在System.ServiceModel.Channels.HttpChannelUtilities.TraceResponseException(例外的例外)在System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest的请求,响应HttpWebResponse,引发WebException responseException,HttpChannelFactory1工厂)在System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest的请求,HttpWebResponse响应,HttpChannelFactory1工厂,引发WebException responseException,channelBinding channelBinding)在System.ServiceModel.Channels.HttpChannelFactory1.HttpRequestChannel.HttpChannelAsyncRequest.ProcessResponse(HttpWebResponse响应,引发WebException responseException)在System.ServiceModel.Channels.HttpChannelFactory1.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult的在System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(I)的System.ServiceModel.Channels.HttpChannelFactory1.HttpRequestChannel.HttpChannelAsyncRequest.OnGetResponse(IAsyncResult result)中AsyncResult结果)在System.Net.LazyAsyncResult.Complete(IntPtr userToken)处System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean preserveSyncCtx)的System.Net.ContextAwareResult.CompleteCallback(Object state)处.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean preserveSyncCtx)System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state)at System.Net.ContextAwareResult.Complete(IntPtr userToken)at at System.Net.LazyAsyncResult.ProtectedInvokeCallback(对象结果,IntPtr userToken)位于系统的System.Net.HttpWebRequest.ProcessResponse()处System.Net.HttpWebRequest.SetAndOrProcessResponse(对象响System.Net.C上的.Net.ConnectionReturnResult.SetResponses(ConnectionReturnResult returnResult) System.Net上的System.Net.LazyAsyncResult.Complete(IntPtr userToken)上的System.Net.Connection.ReadCallbackWrapper(IAsyncResult asyncResult)上的System.Net.Connection.ReadCallback(IAsyncResult asyncResult)上的onnection.ReadComplete(Int32 bytesRead,WebExceptionStatus errorStatus) System.Net.Security._SslStream.ReadFrameCallback上的System.Net.Security._SslStream.ProcessFrameBody(Int32 readBytes,Byte [] buffer,Int32 offset,Int32 count,AsyncProtocolRequest asyncRequest)中的.LazyAsyncResult.ProtectedInvokeCallback(Object result,IntPtr userToken)位于System.Net.FixedSize上的System.Net.FixedSizeReader.CheckCompletionBeforeRead(Int32字节)处的System.Net.As.Pa中,System.Net.LazyAsyncResult.Complete(IntPtr userToken)上的System.Net.AsyncProtocolRequest.CompleteRequest(Int32 result)处的AsyncProtocolRequest asyncRequest) )System.Threading.ExecutionContext.RunInternal的System.Net.ContextAwareResult.CompleteCallback(Object state)(ExecutionContext executionContext,C)系统中的System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,Object状态,Boolean preserveSyncCtx)中的ontextCallback回调,Object state,Boolean preserveSyncCtx)System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态) System.Threading上System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode,UInt32 numBytes,NativeOverlapped * nativeOverlapped)的System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result,IntPtr userToken)中的.Net.ContextAwareResult.Complete(IntPtr userToken) ._IocompletionCallback.PerformIOCompletionCallback(UInt32 errorCode,UInt32 numBytes,NativeOverlapped *pOVERLAP)</ StackTrace> <ExceptionString> System.ServiceModel.Security.MessageSecurityException:使用客户端身份验证方案“Anonymous”禁止HTTP请求 . ---&GT; System.Net.WebException:远程服务器返回错误:(403)Forbidden . 在System.Net.HttpWebRequest.EndGetResponse(IAsyncResult的asyncResult)在System.ServiceModel.Channels.HttpChannelFactory1.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult的结果)---内部异常堆栈跟踪的结尾--- System.Net.WebException,系统, Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089远程服务器返回错误:(403)Forbidden . System.Service.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)at System.ServiceModel.Channels.HttpChannelFactory1.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)</ StackTrace> <ExceptionString> System.Net.WebException:远程服务器返回错误: (403)禁止 . 在System.ServiceModel.Channels.HttpChannelFactory1.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult结果)的System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)处


http://msdn.microsoft.com/sv-SE/library/System.ServiceModel.Diagnostics.ThrowingException.aspx抛出异常 . Myapp.vshost.exe System.ServiceModel.Security.MessageSecurityException,System.ServiceModel,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089 HTTP请求被禁止使用客户端身份验证方案“Anonymous” . 在System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest的请求,响应HttpWebResponse,引发WebException responseException,HttpChannelFactory1工厂)在System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest的请求,响应HttpWebResponse,HttpChannelFactory1工厂,引发WebException responseException,ChannelBinding channelBinding)在System.ServiceModel.Channels.HttpChannelFactory1.HttpRequestChannel.HttpChannelAsyncRequest.ProcessResponse(HttpWebResponse响应,引发WebException responseException)在System.ServiceModel.Channels.HttpChannelFactory1.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult的结果)在System.ServiceModel.Channels.HttpChannelFactory1.HttpRequestChannel.HttpChannelAsyncRequest System.Net.Contex上System.Net.LazyAsyncResult.Complete(IntPtr userToken)的System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult结果)中的.OnGetResponse(IAsyncResult结果) tAwareResult.CompleteCallback(对象状态)在System.Threading.ExecutionContext.RunInternal(的ExecutionContext的ExecutionContext,ContextCallback回调,对象的状态,布尔preserveSyncCtx)在System.Threading.ExecutionContext.Run(的ExecutionContext的ExecutionContext,ContextCallback回调,对象的状态,布尔preserveSyncCtx)在在System.Net.HttpWebRequest的System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result,IntPtr userToken)的System.Net.ContextAwareResult.Complete(IntPtr userToken)上的System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,Object状态) .ProcessResponse()在System.Net.HttpWebRequest.SetResponse(coreResponseData coreResponseData)在System.Net.HttpWebRequest.SetAndOrProcessResponse(对象responseOrException)在System.Net.ConnectionReturnResult.SetResponses(ConnectionReturnResult returnResult)在System.Net.Connection.ReadComplete(的Int32 System.Net.Connection上的bytesRead,WebExceptionStatus errorStatus) . ReadCallback(IAsyncResult的asyncResult)在System.Net.Connection.ReadCallbackWrapper(IAsyncResult的asyncResult)在System.Net.LazyAsyncResult.Complete(IntPtr的userToken)在System.Net.LazyAsyncResult.ProtectedInvokeCallback(对象结果,IntPtr的userToken)在System.Net.Security ._SslStream.ProcessFrameBody(的Int32的ReadBytes,字节[]缓冲液,的Int32偏移的Int32计数,AsyncProtocolRequest asyncRequest)在System.Net.Security._SslStream.ReadFrameCallback(AsyncProtocolRequest asyncRequest)在System.Net.AsyncProtocolRequest.CompleteRequest(的Int32结果)在系统.Net.FixedSizeReader.CheckCompletionBeforeNextRead(字节的Int32)在System.Net.FixedSizeReader.ReadCallback(IAsyncResult的transportResult)在System.Net.LazyAsyncResult.Complete(IntPtr的userToken)在System.Net.ContextAwareResult.CompleteCallback(对象状态)在的System.Threading .ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback回调,对象状态,System.Threading.ExecutionContext.Run上的System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,Object状态,Boolean preserveSyncCtx)中的布尔值preserveSyncCtx)System.Net.ContextAwareResult.Complete上的System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,Object状态) System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32)处的System.Net.LaAsAsyncResult.ProtectedInvokeCallback(对象结果,IntPtr userToken)处的System.Net.LazyAsyncResult.ProtectedInvokeCallback(对象结果,IntPtr userToken)中的(IntPtr userToken)(UInt32 errorCode,UInt32 numBytes,NativeOverlapped * nativeOverlapped) errorCode,UInt32 numBytes,NativeOverlapped * pOVERLAP)</ StackTrace> <ExceptionString> System.ServiceModel.Security.MessageSecurityException:HTTP请求被禁止使用客户端身份验证方案“Anonymous” . ---&GT; System.Net.WebException:远程服务器返回错误:(403)Forbidden . 在System.Net.HttpWebRequest.EndGetResponse(IAsyncResult的asyncResult)在System.ServiceModel.Channels.HttpChannelFactory1.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult的结果)---内部异常堆栈跟踪的结尾--- System.Net.WebException,系统, Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089远程服务器返回错误:(403)Forbidden . System.Service.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)at System.ServiceModel.Channels.HttpChannelFactory1.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)</ StackTrace> <ExceptionString> System.Net.WebException:远程服务器返回错误: (403)禁止 . 在System.ServiceModel.Channels.HttpChannelFactory1.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult结果)的System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)处

我的第一个证书是证书,但两台电脑都匹配 .

我在客户端上创建这样的 Channels :

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 cert = loginType.ClientCertificate;
            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.UsernamePasswordSLL)
            {
                var binding = new NetHttpsBinding("netHttpsBinding");
                binding.Security.Mode = BasicHttpsSecurityMode.Transport;
                if (loginType.LoginType == LoginType.SmartCard)
                    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
                else
                    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);
            if (loginType.LoginType == LoginType.SmartCard)
            {
                v.Credentials.ClientCertificate.Certificate = cert;
                //v.Credentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindByThumbprint, cert.Thumbprint);
            }
            return v;
        }

配置包含扩展,行为和绑定(netHttpsBinding) .

该服务仅从代码创建,而不是从其配置文件创建 .

为什么它不适用于其他计算机?