473,324 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Different behaviour passing array to COM object from WebService and standalone C#

Hello there,

We're new to C# and have noticed a strange behaviour which we don't
yet understand.

We wrote a COM DLL (in VC++ 6.0) which performs some calculation based
on some double arrays passed as input parameters to the DLL through
the SetParams method defined as follows:

interface ICliquet : IPricable
{

HRESULT SetParams([in]long double year_min, long double
monthly_floor,
long double monthly_cap, long double *
drift,
long double * volatility, long double *
dividend,
long double * timespan, long periods,
long double firstmonthquote, long double
rel);
};

(IPricable implements IDispatch)

We can properly add a reference to the COM object through the interop
by VStudio .NET which declares the double* as float64&.

The method works fine when used in a standalone C# application
(declaring the input arrays as...

double [] volatility = new double[1000];

....calls the COM method by...

obj.SetParams(...., ref volatility[0], ...)

The problem arises when doing the same in a C# WebService since the
double arrays are "cleared" (seem to be "zeroed") when passed to the
COM object!

No error is returned (the COM object works "fine" on zeroed input
data!).

It looks like a marshalling problem... the interop assemplies look the
same for both the WS and the standalone solution.

Any hitns?

Thank you!!!

-- Marco & Marcello --
Nov 15 '05 #1
3 4609
I can't help you with the C++ part, but i can tell you, that when i use
WebServices and returning ArrayLists or something, then it gets converted to
object[]. So i would try to pass objects (System.Object) back and forth, and
typecast it in the C++ code, and in the WebService.

:-) Bene

"Marco" <ma***@marcoganz.com> wrote in message
news:c2**************************@posting.google.c om...
Hello there,

We're new to C# and have noticed a strange behaviour which we don't
yet understand.

We wrote a COM DLL (in VC++ 6.0) which performs some calculation based
on some double arrays passed as input parameters to the DLL through
the SetParams method defined as follows:

interface ICliquet : IPricable
{

HRESULT SetParams([in]long double year_min, long double
monthly_floor,
long double monthly_cap, long double *
drift,
long double * volatility, long double *
dividend,
long double * timespan, long periods,
long double firstmonthquote, long double
rel);
};

(IPricable implements IDispatch)

We can properly add a reference to the COM object through the interop
by VStudio .NET which declares the double* as float64&.

The method works fine when used in a standalone C# application
(declaring the input arrays as...

double [] volatility = new double[1000];

...calls the COM method by...

obj.SetParams(...., ref volatility[0], ...)

The problem arises when doing the same in a C# WebService since the
double arrays are "cleared" (seem to be "zeroed") when passed to the
COM object!

No error is returned (the COM object works "fine" on zeroed input
data!).

It looks like a marshalling problem... the interop assemplies look the
same for both the WS and the standalone solution.

Any hitns?

Thank you!!!

-- Marco & Marcello --

Nov 15 '05 #2
Marco,

The declaration that is being created is incorrect. The reason for this
is that the declaration doesn't indicate to the runtime how to correctly
marshal the arrays of doubles.

You will have to declare the COM interface on your own. For the method
that takes double arrays, you will want to do the following:

void SetParams(double year_min, double monthly_floor, double monthly_cap,
[MarshalAs(UnmanagedType.LPArray)]
double[] drift,
[MarshalAs(UnmanagedType.LPArray)]
double[] volatility,
[MarshalAs(UnmanagedType.LPArray)]
double[] dividend,
[MarshalAs(UnmanagedType.LPArray)]
double[] timespan,
int periods,
double firstmonthquote,
double rel);

If the method modifies any of the values, then you will have to use
unsafe code to make the call (to pin the array addresses) or you will have
to marshal the arrays by yourself.

It should be noted that your interface is not a true automation
interface, and should not be derived from IDispatch. Arrays on automation
interfaces are of type SAFEARRAY.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Marco" <ma***@marcoganz.com> wrote in message
news:c2**************************@posting.google.c om...
Hello there,

We're new to C# and have noticed a strange behaviour which we don't
yet understand.

We wrote a COM DLL (in VC++ 6.0) which performs some calculation based
on some double arrays passed as input parameters to the DLL through
the SetParams method defined as follows:

interface ICliquet : IPricable
{

HRESULT SetParams([in]long double year_min, long double
monthly_floor,
long double monthly_cap, long double *
drift,
long double * volatility, long double *
dividend,
long double * timespan, long periods,
long double firstmonthquote, long double
rel);
};

(IPricable implements IDispatch)

We can properly add a reference to the COM object through the interop
by VStudio .NET which declares the double* as float64&.

The method works fine when used in a standalone C# application
(declaring the input arrays as...

double [] volatility = new double[1000];

...calls the COM method by...

obj.SetParams(...., ref volatility[0], ...)

The problem arises when doing the same in a C# WebService since the
double arrays are "cleared" (seem to be "zeroed") when passed to the
COM object!

No error is returned (the COM object works "fine" on zeroed input
data!).

It looks like a marshalling problem... the interop assemplies look the
same for both the WS and the standalone solution.

Any hitns?

Thank you!!!

-- Marco & Marcello --

Nov 15 '05 #3

Nicholas and co.,

Thank you indeed for your useful answers! I reverted to "clean"
automation and used SAFEARRAY to pass my arrays over to (and back
from) the DLL from the C# WebService as well as the standalone app!

Being new to this stuff I found Nichola's explanation about the
marshaller very interesting ineed: I'm going to try your suggestion
asap!

Thank you again and just drop me a message should you pass by Rome:
you deserve a beer!

-- Marco --
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John MacIntyre | last post by:
Hi, I have a page with a series of child pages loaded into an iframe. When I move from page to page, I store an object containing the child's control data in a variable on the main page, then...
5
by: GeRmIc | last post by:
Hi, I am doing an interop from unmanaged code to C#. How do i pass an ArrayList pointer from an unmanaged code, (structres are easily passed by between C# and C). //This is the C code ...
9
by: MMesich | last post by:
I've got an order entry webservice whose WSDL looks like this: <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"...
22
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to...
3
by: SQLScott | last post by:
I have looked all over and I cannot find an example or information on passing a multi-dimensional array. Well, that is not true. I found a close example in C++ but it didn't work when I...
12
by: Noel | last post by:
Hello, I'm currently developing a web service that retrieves data from an employee table. I would like to send and retrieve a custom employee class to/from the webservice. I have currently coded...
5
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
9
by: Greger | last post by:
Hi, I am building an architecture that passes my custom objects to and from webservices. (Our internal architecture requires me to use webservices to any suggestion to use other remoting...
8
by: amazon | last post by:
I have a following structure that I am using with array list: Private Structure arrayliststruct Public Name As String Public value As String Public type As String End Structure and following...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.