 |
SoftTree Technologies
Technical Support Forums
|
|
Author |
Message |
Joshua Youngblood
Joined: 14 Apr 2006 Posts: 82 Country: United States |
|
Use 24x7 JDL Commands from C# |
|
I've been trying to create an object in C# so that I can use the JDL commands. Do you know how I would do that? Here is how I'm currently attempting to do it:
 |
 |
public System.Type typeRemote24x7 = System.Type.GetTypeFromProgID("24x7 Remote Control");
object objRemote24x7;
objRemote24x7 = Activator.CreateInstance(typeRemote24x7);
|
|
|
Wed Jun 04, 2008 4:48 pm |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
I'm not really sure. I've never done this before in C#. Just as a suggestion, please check if typeRemote24x7 is not null
 |
 |
if (typeRemote24x7 == null)
..... handle this error
else
objRemote24x7 = Activator.CreateInstance(typeRemote24x7); |
iI you get null, it is likely the system cannot find COM object registration in the registry. If you don't get null, check for exceptions when creating an instance of the object.
|
|
Wed Jun 04, 2008 5:20 pm |
|
 |
Joshua Youngblood
Joined: 14 Apr 2006 Posts: 82 Country: United States |
|
|
|
The value is not null in either case. I am writing my application using Visual Studio 2005, and the debugger says that typeRemote24x7 is equal to "System.__ComObject". When I try to compile while using "typeRemote24x7.OpenSession", it says, "'object' does not contain a definition for 'OpenSession'".
The 24x7 COM documentation says that most programming languages should create an object using the PROGID of "24x7 Remote Control". Is the correct when using C#?
Also, Is there a specific ".dll" file that I need to be referencing?
|
|
Thu Jun 05, 2008 11:20 am |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
Yes, this is fine. Please try the following test. Create a text file called test.js with the following text
WScript.Echo("Ready to test. Click OK to continue.\n\n");
//var remote24x7 = new ActiveXObject("w24x7ASP.jsRemote24x7");
//var remote24x7 = WScript.CreateObject("w24x7ASP.jsRemote24x7");
 |
 |
var remote24x7 = WScript.CreateObject("24x7 Remote Control");
if (!remote24x7)
{
var LastError = "Cannot load 24x7 Remote Control";
WScript.Echo(LastError);
}
else
{
var RetCode = remote24x7.OpenSession("Demo", "test", "WinSock", "LocalHost", "1096", "Retry=3", true);
WScript.Echo("OpenSession: Return Code and error: " + RetCode + " -- " + remote24x7.LastError);
} |
Save it, and double click to run. If you get an error "cannot load..." you have a problem with the COM control registration. If you get other message, you are ok.
|
|
Thu Jun 05, 2008 11:34 am |
|
 |
Joshua Youngblood
Joined: 14 Apr 2006 Posts: 82 Country: United States |
|
|
|
I got the second message.
|
|
Thu Jun 05, 2008 11:43 am |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
If you can do it in VBScript and JScript, you should be able to do it in any other full blown programming language supporting COM automation, including C#
I'll try to dig how to do it, but I cannot promise quick help
|
|
Thu Jun 05, 2008 11:53 am |
|
 |
Joshua Youngblood
Joined: 14 Apr 2006 Posts: 82 Country: United States |
|
|
|
Thanks for your help. I'll also let you know if I find anything.
|
|
Thu Jun 05, 2008 11:57 am |
|
 |
Joshua Youngblood
Joined: 14 Apr 2006 Posts: 82 Country: United States |
|
|
|
We have it working, now. Here's how to do it:
 |
 |
Type typeRemote24x7 = Type.GetTypeFromProgID("24x7 Remote Control");
objRemote24x7 = Activator.CreateInstance(typeRemote24x7);
// To execute a 24x7 method, define an array of arguments. Then,
// pass the method name, the newly created 24x7 object, and the arguments to InvokeMember.
Object[] methodArgs = {"userName", "", "Winsock", "localhost", "1096", "", false};
Object returnValue = typeRemote24x7.InvokeMember("OpenSession", System.Reflection.BindingFlags.InvokeMethod, null, objRemote24x7, methodArgs);
// Because OpenSession returns a long, the returnValue object can be converted to the same/similar type.
Int64 OpenSessionRetValue = Convert.ToInt64(returnValue);
//---------------------------------------------------------------------------------------------------------------------------------
// InvokeMember is also used to get attribute values, but only the attribute name and 24x7 object are needed.
returnValue = typeRemote24x7.InvokeMember("LastError", System.Reflection.BindingFlags.InvokeMethod, null,
objRemote24x7, null);
// Again, the returnValue can be converted to the appropriate type.
String LastErrorMessage = returnValue.ToString();
|
|
|
Thu Jun 05, 2008 5:19 pm |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|