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

InvokeMethod from C#/CSharp for a function with Struct type argument

New Here ,
May 31, 2012 May 31, 2012

I am in the process of creating a .Net utility to help us with some ColdFusion functions and in the .Net utility I still need to call some ColdFusion functions.  The function is expecting a Struct type.

After much internet searching I have been unable to determine what type of object I need to use in C#/CSharp that will convert to the type="Struct" argument.

I receive the following error in C#/CSharp when trying to call the InvokeMethod method.

"... cannot convert to type 'Map'"

I have tried to use HashTable, DataTable, etc...

Is there anyway I can invoke a ColdFusion function with a Struct type argument from C#/CSharp?

3.7K
Translate
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 ,
May 31, 2012 May 31, 2012

jmwolman wrote:

Is there anyway I can invoke a ColdFusion function with a Struct type argument from C#/CSharp?

Yes, write a web service in ColdFusion, and then invoke it from C# or, indeed, from wherever you like. Otherwise, you cannot expect C# to call ColdFusion or vice versa.

Translate
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
New Here ,
May 31, 2012 May 31, 2012

I have a ColdFusion web service I am dynamically connecting to the wsdl file from C# and trying to call one of the ColdFusion web service functions from with my C# utility

Part of my ColdFusion code:

cfcomponent displayname="componentName" output="false">

<cffunction name="ComponentFunction" returntype="struct">

  <cfargument name="Argument1" type="Struct">

The problem I am having is when I invoke the "ComponentFunction" function from within my C# utilty I am having problems trying to determine what type of C# object I need to send for the Argument1 argument.  This is where I have tried to use a HashTable and DataTable and an Array, but I get the cannot convert to 'Map' error.

Translate
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 ,
May 31, 2012 May 31, 2012

C# doesn't know what a ColdFusion struct is, naturally. Experiment with: <cfargument name="Argument1" type="any">.

Translate
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
LEGEND ,
Jun 01, 2012 Jun 01, 2012

C# doesn't know what a ColdFusion struct is, naturally. Experiment with: <cfargument name="Argument1" type="any">.

That's not gonna help: the OP still needs to pass a struct in.  It's not the type value on the argument tag that's the problem, it's that they don't know how to construct something in C# that CF will understand as being a struct.

--

Adam

Translate
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 ,
Jun 01, 2012 Jun 01, 2012

Adam Cameron. wrote:

C# doesn't know what a ColdFusion struct is, naturally. Experiment with: <cfargument name="Argument1" type="any">.

That's not gonna help: the OP still needs to pass a struct in.  It's not the type value on the argument tag that's the problem, it's that they don't know how to construct something in C# that CF will understand as being a struct.

My point is that native C# code cannot pass an argument of type struct (strictly speaking, of type coldfusion.runtime.Struct).

Translate
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
LEGEND ,
Jun 01, 2012 Jun 01, 2012

And you're calling componentFunction as a web service, yes?

The WDSL for the CFC will tell you how to construct the input values.  That said, I suck at interpretting WSDL into something meaningful, so I can't help you with that side of thins.  As an aside... at the end of the day web services are platform-agnostic: it's not like a web service call is actually passing a struct (which is an in-memory conceit); it's just passing a string in a previously-agreed-upon format which CF then converts to a struct.  System interoeprability is the raison d'etre of web services, after all.

That said, I'm surprised a HashTable doesn't work.  Does C# have the notion of a HashMap?  [Googles...]

I found this:

http://stackoverflow.com/questions/1273139/c-sharp-java-hashmap-equivalent

Maybe try a Dictionary?

--

Adam

Translate
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
New Here ,
Jun 01, 2012 Jun 01, 2012

Thanks Adam.  Yes I tried the following C# objects:  Dictionary<String, String>, System.Collections.Hashtable, DataTable table, Class structure, and ArrayList arrayTable.

All of which gave me the cannot convert to 'Map' error when invoking the function from C#.
Because we have to dynamically determine the web service based on selected information we are using the System.Reflection MethodBase class to call MethodInfo.Invoke

Which could be causing the issue since I am not straightout referencing one WSDL file.

Translate
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
LEGEND ,
Jun 01, 2012 Jun 01, 2012

Which could be causing the issue since I am not straightout referencing one WSDL file.

Sure, but you could still look at the WSDL to work out what it is you need to pass it.

Dunno what else to suggest though, sorry.

--

Adam

Translate
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
New Here ,
Jun 01, 2012 Jun 01, 2012

The WSDL file is showing: 


<
wsdl:part name="ReturnValue" type="apachesoap:Map" />

Translate
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
LEGEND ,
Jun 01, 2012 Jun 01, 2012

I googled "c# apachesoap:Map".

One of the matches was this:

http://forums.asp.net/t/1445135.aspx/1?C+and+ColdFusion8+web+services

It might pay to do a bit more googling though, I'm sure you'll find something.  Well: "sure" is overstating it.  You might find something 😉

From this point though, all I'd be doing to help is googling stuff.  And I figure you could probably do as good a job of that as I can, so will leave it to you.

Do report back if you work it out though: you might save someone else some time down the track...

Sorry to not be able to help further.

--
Adam

Translate
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 ,
Jun 01, 2012 Jun 01, 2012

jmwolman wrote:

I tried the following C# objects:  Dictionary<String, String>, System.Collections.Hashtable, DataTable table, Class structure, and ArrayList arrayTable.

And the type KeyValuePair?

Translate
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
New Here ,
Jun 01, 2012 Jun 01, 2012

Correct, the KeyValuePair gave me the same error, cannot convert to 'Map'.  I am still looking and researching, but thanks for all the suggestions and help.  Google is the word!  I just hope The Great Google Machine can help.

Translate
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 ,
Jun 01, 2012 Jun 01, 2012
LATEST

According to the conversion rules for .NET and Java in the ColdFusion documentation, System.Collections.Hashtable is the closest .NET type to a CF struct.

Translate
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