WCF gives an unsecured or incorrectly secured fault error

前端 未结 21 2319
予麋鹿
予麋鹿 2020-11-28 23:09

I am trying to consume a remote svc web service. I created the proxy class using svcutil.exe, and after that I\'ve added that class to my console application, b

相关标签:
21条回答
  • 2020-11-28 23:30

    Try with this:

    catch (System.Reflection.TargetInvocationException e1)  
          String excType   
          excType = e1.InnerException.GetType().ToString()  
          choose case excType  
                    case "System.ServiceModel.FaultException"  
                              System.ServiceModel.FaultException e2  
                              e2 = e1.InnerException  
                              System.ServiceModel.Channels.MessageFault fault  
                              fault = e2.CreateMessageFault()  
                              ls_message = "Class: uo_bcfeWS, Method: registraUnilateral ~r~n" + "Exception(1): " + fault.Reason.ToString()   
                              if (fault.HasDetail) then  
                                        System.Xml.XmlReader reader  
                                        reader = fault.GetReaderAtDetailContents()  
                                        ls_message += " " + reader.Value  
                                        do while reader.Read()  
                                                  ls_message += reader.Value  
                                        loop  
                              end if  
                    case "System.Text.DecoderFallbackException"  
                              System.Text.DecoderFallbackException e3  
                              e3 = e1.InnerException  
                              ls_message = "Class: uo_bcfeWS, Method: registraUnilateral ~r~n" + "Exception(1): " + e3.Message   
                    case else  
                              ls_message = "Class: uo_bcfeWS, Method: registraUnilateral ~r~n" + "Exception(1): " + e1.Message  
          end choose  
          MessageBox ( "Error", ls_message )  
          //logError(ls_message)  
          return false  
    
    0 讨论(0)
  • 2020-11-28 23:32

    For what it's worth - I also had this error and found it was caused by the connection string in the web services web.config being set to connect to the wrong machine.

    0 讨论(0)
  • 2020-11-28 23:33

    Try changing your security mode to "transport".

    You have a mismatch between the security tag and the transport tag.

    0 讨论(0)
  • 2020-11-28 23:35

    You have obviously a problem with the WCF security subsystem. What binding are you using? What authentication? Encryption? Signing? Do you have to cross domain boundaries?

    A bit of goggling further reveals that others are experiencing this error if the clocks of client and server are out of sync (more than about five minutes) because some security schemata rely on synchronized clocks.

    0 讨论(0)
  • 2020-11-28 23:36

    I had to change the SecurityMode to Message (WSHttpBinding), before it worked. i.e.

    _wcf = new ServiceRequestClient(new WSHttpBinding(SecurityMode.Message),                     
           new EndpointAddress(_wcfRequestServerAddress));
    
    0 讨论(0)
  • 2020-11-28 23:38

    Although your problem was solved with one of the above solutions, for the benefit of others, here's another option.

    You also can get this exception when incorrect credentials are passed to a basic endpoint (SOAP 1.1) that uses username message credentials as you are. For example, if you are calling the service from code and do something like this:

    var service = new TestService();
    
    service.ClientCredentials.UserName.UserName = "InvalidUser";
    service.ClientCredentials.UserName.Password = "InvalidPass";
    

    This is different from a WSHTTP endpoint (SOAP 1.2) that throws an AccessDeniedException when invalid credentials are passed through. I personally find the message contained herein a little misleading (it certainly cost me a few minutes the first time I encountered it for this reason) but the underlying cause was clear once I consulted the WCF Diagnostic Trace Logs.

    0 讨论(0)
提交回复
热议问题