0

Is it possible to do this task using C#?

Global Const COMPLUS_SERVER As String = "http://myserver"

Sub Test()
    Set objRDS = CreateObject("RDS.Dataspace")
    Set objCLS = objRDS.CreateObject("MY_System", COMPLUS_SERVER)
    Set ListNames = objCLS.LstOBSReasons("databaseserver", "databasename", 5)
End Sub

I've tried with Activator.CreateInstance(Type.GetTypeFromProgID("")); with no success, besides I would like to know in another way that I can connect to my business object.

Thanks in advance!

marc_s
  • 675,133
  • 158
  • 1,253
  • 1,388

1 Answers1

0

It should be possible, first you need to add the Microsoft Remote Data Services Library to your project's references. You will find it under the COM tab. You can then create the RDS.DataSpace class by doing:

DataSpaceClass objRDS = new RDS.DataSpaceClass();
dynamic objCLS = objRDS.CreateObject("MY_System", "http://myserver");
dynamic listNames = objCLS.LstOBSReasons("databaseserver", "databasename", 5);

The only tricky part is you might not be able to call the resulting object through the dynamic invocation (and I assume you are using C#4). If you can't you will need to also import the types for your business object. For example look at something like this for more information on implementing COM interop.

tyranid
  • 12,552
  • 1
  • 29
  • 32
  • Great!, In fact, i'm using C# 3.0. How can I deal with this? Note that can't use *dynamic* –  Apr 13 '12 at 14:44
  • 1
    You will need to find your interface you are using, implement it with reference to that article, then you can cast the object returned from CreateObject into that interface. If you have a type library for the business object you should be able to load that in as a reference in visual studio itself and it will do it all for you (or there is http://msdn.microsoft.com/en-us/library/tt0cf3sx%28v=vs.80%29.aspx) which will do it as well. – tyranid Apr 13 '12 at 17:13