Need assistance in event handling received by configuration server while querying for person details.
I am new to platform SDK .net. I am trying to query person details from configuration server using platform SDK .net. We are able to open connection with configuration server and send request "RequestReadObjects" for person details. I am not sure what mistake i am making while event handling, Hence not receiving anything from configuration server. Please find below my SDK .net code for event handling code.
try
{
ProtocolManagementService protocolManagementService = new ProtocolManagementService();
ConfServerConfiguration confserv = new ConfServerConfiguration("confserv");
confserv.Uri = new Uri("tcp://<cfg_host>:2020");
confserv.ClientApplicationType = CfgAppType.CFGSCE;
confserv.ClientName = "default";
confserv.UserName = "<username>";
confserv.UserPassword = "<password>";
protocolManagementService.Register(confserv);
EventBrokerService eventbrokerservice;
eventbrokerservice = new EventBrokerService(protocolManagementService.Receiver);
eventbrokerservice.Register(this.OnConfEventError, new MessageIdFilter(EventError.MessageId));
eventbrokerservice.Register(this.OnConfEventObjectsRead, new MessageIdFilter(EventObjectsRead.MessageId));
eventbrokerservice.Register(this.OnConfEventObjectsSent, new MessageIdFilter(EventObjectsSent.MessageId));
protocolManagementService["confserv"].Open();
KeyValueCollection filterkey = new KeyValueCollection();
filterkey.Add("user_name", "rajnish");
RequestReadObject requestreadObject = RequestCreateObject.Create((int)CfgObjectType.CFGPerson, filterkey);
IMessage msg = protocolManagementService["confserv"].Request(requestreadObject);
Console.WriteLine("response "+msg);
}
catch (Exception X)
{
Console.WriteLine(X);
Console.ReadLine();
}
Code for event handling:-
private void OnConfEventObjectsRead(IMessage theMessage)
{
Console.WriteLine("I'm event!");
EventObjectsRead objectsRead = theMessage as EventObjectsRead;
StringBuilder xmlAsText = new StringBuilder();
XmlWriterSettings xmlSettings = new XmlWriterSettings();
xmlSettings.Indent = true;
using (XmlWriter xmlWriter =
XmlWriter.Create(xmlAsText, xmlSettings))
{
XDocument resultDocument = objectsRead.ConfObject;
resultDocument.WriteTo(xmlWriter);
}
Console.WriteLine("This is the response:\n"
+ xmlAsText.ToString() + "\n\n");
// Console.ReadLine();
}
private void OnConfEventError(IMessage theMessage)
{
EventError eventError = theMessage as EventError;
Console.WriteLine("error");
}
private void OnConfEventObjectsSent(IMessage theMessage)
{
Console.WriteLine("I'm event!");
}