c# custom method
This sample is available for
download as a Visual Studio project.
A c# custom method implementation needs to meet the following requirements in order for the generated code to be able to invoke it:
-
The implementation file needs to include the namespace System.Data.Odbc.
-
The implementation file needs to include the namespace of the automatically generated interface class. It's named <prefix>.DB.<interface name>.
-
The implementation file must contain the namespace assigned to the RISE custom method.
-
The implementation namespace must contain (implement) the class assigned to the RISE custom method.
-
The implementation class must provide a constructor accepting an OdbcCommand unless the NoDatabase property has been set to True, in which case the default constructor is called instead, see samples below.
-
The implementation class must implement methods having the same signature (name, arguments and output) as the corrresponding RISE custom method.
Suppose we create an interface, MyInterface, in a RISE model having prefix MyPrefix. MyInterface is then assigned a method, MyMethod, with a signature according to the picture below.
We also specify, in the RISE Editor, that the method should use the class MyClass in the namespace MyNamespace. Once all this is done we generate the interface. The generated code will now attempt to call an implementation corresponding to the below sample code.
using System.Data.Odbc;
using MyPrefix.DB.MyInterface; // Namespace of generated interface
namespace MyNamespace
{
public class MyClass
{
private OdbcCommand _cmd = null;
public MyClass(OdbcCommand cmd)
{ // cmd is connected and ready for calling the MyPrefix database
_cmd = cmd;
}
public returnMyMethod MyMethod(int a)
{
returnMyMethod rv = new returnMyMethod();
rv.b = "MyMethod got "+ a.ToString(); // Do whatever!
return rv;
}
}
} |
If the custom method is specified as not using the solution database the below, simplified, template is expected.
using MyPrefix.DB.MyInterface; // Namespace of generated interface
namespace MyNamespace
{
public class MyClass
{
public MyClass()
{
}
public returnMyMethod MyMethod(int a)
{
returnMyMethod rv = new returnMyMethod();
rv.b = "MyMethod got "+ a.ToString(); // Do whatever!
return rv;
}
}
} |
In a .NET web service you should either compile your web service application consisting of both the generated code and the custom code or you can place the custom code file directly in the App_Code sub-directory for dynamic loading.