如何解决wcf通信异常中的“不安全或不正确安全的故障”?

时间:2012-06-19 06:57:40

标签: c# wcf web-services windows-services security

我尝试在Windows服务的任何机器上使用远程dll覆盖wcf服务。但是wcf服务返回给我这个错误:

CommunicationException:从另一方收到了不安全或不正确安全的故障。请参阅内部FaultException以获取故障代码和详细信息。

我的wcf服务运作良好。我也调用我的wcf服务调用PROCESS.dll。我动态地调用wcf服务:


  public static ApplicationHostServiceClient CreateApplicationHostService()
        {
            try
            {
                int maxDifference = 300;
                WSHttpBinding binding = new WSHttpBinding();
                binding.MaxReceivedMessageSize = int.MaxValue;
                binding.MaxBufferPoolSize = int.MaxValue;
                binding.ReaderQuotas.MaxArrayLength = int.MaxValue;
                CustomBinding myCustomBinding = new CustomBinding(binding); //CreateMultiFactorAuthenticationBinding(binding);

                // Set the maxClockSkew
                var security = myCustomBinding.Elements.Find();
                security.LocalClientSettings.MaxClockSkew = TimeSpan.FromMinutes(maxDifference);
                security.LocalServiceSettings.MaxClockSkew = TimeSpan.FromMinutes(maxDifference);

                // Set the maxClockSkew
                var secureTokenParams = (SecureConversationSecurityTokenParameters)security.ProtectionTokenParameters;
                var bootstrap = secureTokenParams.BootstrapSecurityBindingElement;
                bootstrap.LocalClientSettings.MaxClockSkew = TimeSpan.FromMinutes(maxDifference);
                bootstrap.LocalServiceSettings.MaxClockSkew = TimeSpan.FromMinutes(maxDifference);

                // Update the binding of the endpoint
               // service.Description.Endpoints[0].Binding = myCustomBinding;




                EndpointAddress endpoint = new EndpointAddress(new Uri(ProcessApplication.Serverparameters.BaseServiceHost + "/Service/ApplicationHostService.svc"));
                ApplicationHostServiceClient ser = new ApplicationHostServiceClient(myCustomBinding, endpoint);

                return ser;
            }
            catch (Exception exc)
            {

                ProcessApplication.Application.OnError("CreateApplicationHostService is not              succeeded.", "CreateApplicationHostService", exc);
                return null;
            }

        }

但是发生了以上错误。如何解决我的安全异常?

0 个答案:

没有答案