IdeaBlade DevForce 2010 Help Reference
ServerMethodDelegate Delegate
See Also  Example Send Feedback
IdeaBlade.EntityModel Assembly > IdeaBlade.EntityModel Namespace : ServerMethodDelegate Delegate



principal
Represents the calling user
serverEntityManager
A server-side EntityManager (this is not the EntityManager on which the InvokeServerMethod call was made)
args
User-defined arguments
Defines a delegate that a client uses to call a method on the server. EntityManager.InvokeServerMethod

Syntax

Visual Basic (Declaration) 
Public Delegate Function ServerMethodDelegate( _
   ByVal principal As IPrincipal, _
   ByVal serverEntityManager As EntityManager, _
   ByVal ParamArray args() As Object _
) As Object
Visual Basic (Usage)Copy Code
Dim instance As New ServerMethodDelegate(AddressOf HandlerMethod)
C# 
public delegate object ServerMethodDelegate( 
   IPrincipal principal,
   EntityManager serverEntityManager,
   params object[] args
)
C++/CLI 
public delegate Object^ ServerMethodDelegate( 
   IPrincipal^ principal,
   EntityManager^ serverEntityManager,
   ... array<Object^>^ args
)

Parameters

principal
Represents the calling user
serverEntityManager
A server-side EntityManager (this is not the EntityManager on which the InvokeServerMethod call was made)
args
User-defined arguments

Return Value

Any serializable type

Example

C#Copy Code
// Sample showing invocation of server method
EntityManager mgr = new DomainModelEntityManager();
int orderId = 10250;
bool mailSent = (bool) mgr.InvokeServerMethod(Order.EmailOrderInfo, orderId);

// sample method defined in Order class
public class Order {
//...
  // ServerMethodDelegate method, called from client
  [AllowRpc]
  public static Object EmailOrderInfo(IPrincipal pPrincipal, EntityManager pPm, params Object[] pArgs) {
    int orderId = Convert.ToInt32(pArgs[0]);

    // build and send an email message 
    string from = "sales@mycompany.com";
    string to = "customer@yourcompany.com";
    System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(from, to);
    msg.Subject = "Order Information";
    msg.Body = string.Format("Order id = {0} has been shipped", orderId);

    System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("localhost");
    try {
      mailClient.Send(msg);
    } catch (Exception e) {
      TraceFns.WriteLine(e.Message);
      return false;
    }
    return true;
 }
}
Visual BasicCopy Code
' Sample showing invocation of server method
Dim mgr As EntityManager As New DomainModelEntityManager()
Dim orderId As Integer = 10250
Dim mailSent As Boolean = CBool(mgr.InvokeServerMethod(Order.EmailOrderInfo, orderId))

' sample method defined in Order class
Public Class Order 
'...
  Public Shared<AllowRpc()>  _
  Function EmailOrderInfo(pPrincipal As IPrincipal, pManager As EntityManager, ParamArray pArgs() As [Object]) As [Object]
    Dim orderId As Integer = Convert.ToInt32(pArgs(0))
   
    ' build and send an email message 
    Dim from As String = "sales@mycompany.com"
    Dim [to] As String = "customer@yourcompany.com"
    Dim msg As New System.Net.Mail.MailMessage(from, [to])
   
    msg.Subject = "Order Information"
    msg.Body = String.Format("Order id = {0} has been shipped", orderId)
   
    Dim client As New System.Net.Mail.SmtpClient("localhost")
    Try
      client.Send(msg)
    Catch e As Exception
      TraceFns.WriteLine(e.Message)
      Return False
   End Try
   Return True
 End Function 
End Class

Remarks

Any method which will be invoked via the EntityManager.InvokeServerMethod call must use this delegate signature.

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© 2013 All Rights Reserved.