Web Extensibility Download Part 3 - Extending Client-side code behavior


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public class CreateExtension : IEndpointBehaviorExtender
  2. {
  3. #region IEndpointBehaviorExtender Members
  4.  
  5. public string Action
  6. {
  7. get { return "Expense/Create"; }
  8. }
  9.  
  10. public void BeforeSendRequest(string action, ref Message request, IDictionary<string, object> formData)
  11. {
  12. // create a strongly type version of the message
  13. ExpenseCreateRequestMessage req = MessageConverter<ExpenseCreateRequestMessage>.GetObjectFromMessage(action, request);
  14.  
  15. // the data contract already has additonal collections (dictionaries) so that
  16. // additional data can be stored along with the default contract.
  17.  
  18. // Try to make 'key' as unique as possible so that only you could identify it. Perhaps add your name / intials or BP Channel Name
  19. if (!req.Expense.FieldExtensions.ContainsKey("RBC_DateExpenseCreated"))
  20. req.Expense.FieldExtensions.Add("RBC_DateExpenseCreated", DateTime.Now.ToLongDateString());
  21.  
  22. // replace the message request with new one
  23. request = MessageConverter<ExpenseCreateRequestMessage>.SetMessageFromObject(action, req, request.Headers.MessageVersion);
  24. }
  25.  
  26. public void AfterReceiveReply(string action, Message reply)
  27. {
  28. // convert the message to its strong type (as described in contract library)
  29. ExpenseCreateResponseMessage response = MessageConverter<ExpenseCreateResponseMessage>.GetObjectFromMessage(action, reply);
  30.  
  31. // do stuff with respones...
  32. }
  33.  
  34. #endregion
  35. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.