8 Replies Latest reply on Oct 5, 2011 10:40 AM by -==cfSearching==-

    .NET init method when there are multiple constructors

    SteveTX

      So I am trying to work with some .NET objects. I've run into a situation where I can create the object but I'm getting an error when I call the init method:

       

      "Unable to find a constructor for class Microsoft.Web.Services3.Security.Tokens.BinarySecurityToken that accepts parameters of type ( java.lang.String, java.lang.String )"

       

      (I'm assuming that the "java.lang.String" referenced in the message is just from CF and that the .NET object is not getting an actual java.lang.String passed to it. And I've also gotten the error passing a .NET object as the init argument.)

       

      This particular object has a number of constructor methods that take different arguments. So I guess I'm wondering if there's some issue with init not finding the proper constructor, and if so, what I can do about it. Anyone had any experience like this?

        • 1. Re: .NET init method when there are multiple constructors
          BKBK Adobe Community Professional & MVP

          There is indeed an issue with not finding the proper constructor for BinarySecurityToken. Could you show us the code?

          • 2. Re: .NET init method when there are multiple constructors
            -==cfSearching==- Level 4

            some issue with init not finding the proper constructor

             

            The error may be a bit misleading. That constructor is marked as protected (similar to package level access in ColdFusion). Meaning you are not allowed to instantiate it from outside the package (in this case from CF). It is also an abstract class. You need to use one of the concrete classes that extends BinarySecurityToken instead. Those will have public constructors.

            • 3. Re: .NET init method when there are multiple constructors
              SteveTX Level 1

              I've tried using the X509SecurityToken with the same results. Code sample below.

               

              <cfscript>

              webService = CreateObject(".NET","System.Web.Services.WebService","C:\Windows\Microsoft.NET\Framework\ v2.0.50727\System.Web.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Web.Service s.dll");

              x509Store = CreateObject(".NET","System.Security.Cryptography.X509Certificates.X509Store");

              x509Cert2 = CreateObject(".NET","System.Security.Cryptography.X509Certificates.X509Certificate2");

              binaryToken = CreateObject(".NET","Microsoft.Web.Services3.Security.Tokens.X509SecurityToken","C:\Progr am Files\Microsoft WSE\v3.0\Microsoft.Web.Services3.dll");

              MessageSigX509 = CreateObject(".NET","Microsoft.Web.Services3.Security.MessageSignature","C:\Program Files\Microsoft WSE\v3.0\Microsoft.Web.Services3.dll");

              MessageSigUname = CreateObject(".NET","Microsoft.Web.Services3.Security.MessageSignature","C:\Program Files\Microsoft WSE\v3.0\Microsoft.Web.Services3.dll");

              storeLoc = CreateObject(".NET","System.Security.Cryptography.X509Certificates.StoreLocation");

              storeName = CreateObject(".NET","System.Security.Cryptography.X509Certificates.StoreName");

              openFlags = CreateObject(".NET","System.Security.Cryptography.X509Certificates.OpenFlags");

              findType = CreateObject(".NET","System.Security.Cryptography.X509Certificates.X509FindType");

              str = CreateObject(".NET","System.String");

              x509Store.init(storeName.My,storeLoc.LocalMachine);

              x509Store.Open(openFlags.ReadOnly);

              certs = x509Store.Get_Certificates();

              webCerts = certs.Find(findType.FindBySubjectKeyIdentifier,"*******************************",false);

              webCert = x509Cert2.init(webCerts.Get_Item(0));

              binaryToken.init(webCert);

               

              </cfscript>

              • 4. Re: .NET init method when there are multiple constructors
                -==cfSearching==- Level 4

                First, can you post the line number where the error occurs and the latest error message?

                 

                Second, if the error is occuring on the call to binaryToken.init(webCert); dump webCert . Are you sure you are passing in the correct object?

                 

                Message was edited by: -==cfSearching==-

                • 5. Re: .NET init method when there are multiple constructors
                  SteveTX Level 1

                  Yes it's binaryToken.init(webCert); that is throwing the error about not finding a constructor.

                   

                  I've done dumps of all the objects. The webCert object looks good to me. The code seems to be finding the cert in the x509Store. The actual error I get in this instance is:

                   

                  Unable to find a constructor for class Microsoft.Web.Services3.Security.Tokens.X509SecurityToken that accepts parameters of type ( System.Security.Cryptography.X509Certificates.X509Certificate2 ).

                  • 6. Re: .NET init method when there are multiple constructors
                    -==cfSearching==- Level 4

                    Nothing is jumping out as blatantly wrong so far. But the two typical causes I have run into are wrong class or dll/library mix up. 

                     

                     

                    Does the code work when you run it in .net?

                     

                     

                    -Leigh

                    • 7. Re: .NET init method when there are multiple constructors
                      SteveTX Level 1

                      I haven't attempted to run it in .NET. It may come to that though.

                      • 8. Re: .NET init method when there are multiple constructors
                        -==cfSearching==- Level 4

                        Honestly, unless it is a really big hassle to do so, I would try that first.  A small test class that duplicates your CF code should tell you very quickly if the problem is with the CF layer or just your syntax or library references.

                         

                         

                        -Leigh