473,808 Members | 2,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4631
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***@marcogan z.com> wrote in message
news:c2******** *************** ***@posting.goo gle.com...
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(doubl e year_min, double monthly_floor, double monthly_cap,
[MarshalAs(Unman agedType.LPArra y)]
double[] drift,
[MarshalAs(Unman agedType.LPArra y)]
double[] volatility,
[MarshalAs(Unman agedType.LPArra y)]
double[] dividend,
[MarshalAs(Unman agedType.LPArra y)]
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************* *@exisconsultin g.com

"Marco" <ma***@marcogan z.com> wrote in message
news:c2******** *************** ***@posting.goo gle.com...
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
13364
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 use that data to populate the controls when the child page is opened again. One of these objects contains an Array, and the page reloads fine using myArray, myArray, etc... But when I try perform some array methods on it (i.e.slice) ... it does...
5
7209
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 NameStruct lnames; //This is a structure in C#
9
8272
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" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <OrderSubmit xmlns="http://tempuri.org/WebServices/beta"> <varCustNum>string</varCustNum> <varPassword>string</varPassword>
22
25610
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 compile. <WebMethod()> _ Public Function VerifySku(ByVal skus As XmlDataDocument) As DataSet Test program : Dim cartSet As DataSet cartSet = ws.VerifySku(cartSet)
3
9349
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 "converted it" to VB.Net. My receiving method looks like this: Public DoIt(ByRef Array( , ) as string) as boolean but what I am not clear on is what the parameter looks like in my calling routine:
12
5344
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 the custom employee class and have built it as a separate library (employee.dll). This employee.dll is being referenced by both the web service and the windows application. I face the following problem when I send this class to the webservice.
5
19604
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 having a problem in the calling program. I searched online and found suggestions that I return an Array instead so I modified my code (below) to return an Array instead of an ArrayList. Now I get the message when I try to run just my webservice...
9
3807
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 techniques are not feasible) The question is; Given that I have a Person object with a private set for id. What is the recommended approac in passing that object to the web service
8
4399
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 function to format arraylist the way I want and calling it from button click event: Private Function formatarray(ByVal inarray As ArrayList, _
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10631
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7651
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3859
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.