• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

.NET init method when there are multiple constructors

Explorer ,
Sep 23, 2011 Sep 23, 2011

Copy link to clipboard

Copied

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?

TOPICS
Advanced techniques

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 04, 2011 Oct 04, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 04, 2011 Oct 04, 2011

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 04, 2011 Oct 04, 2011

Copy link to clipboard

Copied

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.Services.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:\Program 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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 04, 2011 Oct 04, 2011

Copy link to clipboard

Copied

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==-

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 04, 2011 Oct 04, 2011

Copy link to clipboard

Copied

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 ).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 04, 2011 Oct 04, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 05, 2011 Oct 05, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 05, 2011 Oct 05, 2011

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation