PI Notification and Web Service

Version 1

    Hi everyone.

     

    I have a PI Notification built programmatically which condition involves a comparison between a pi tag and a constant value. The point is that I want to call a Web Service I have also built as delivery endpoint of a contact in AF, passing the value of the pi tag that triggered the notification as this web service's parameter.

     

    Is there any way to map the output of the notification to the input of the web service? If not, how can I achieve my goal?

     

    Thanks in advance.

     

    Ernesto,

     

    Please see this thread and this one that explain how you can use a web service as the delivery endpoint for your PI Notification.

     

    Thanks for the asnwer Ahmad, but I haven't found what I was looking for, though close. More specifically, I want to set those "Value" fields of the web service subscribed to a notification programmatically, so the web service method will be invoked with the value of the pi tag that has risen the notification. Is it possible?

     

    Ernesto,

     

    OK now I understand what you are looking for better. You can at any moment in time go through active notification instance (as well as non-active ones) and use GetInputs() method to retrieve the attributes of the notification. Please see this thread for an example. Some more general explanations can also be found in AN SDK User Manual as well as in this thread.

     

    Hi Ahmad, thanks again for your help. I managed to do what I needed but only partially.

     

    Now, I have the contents of my notifications set correctly, but still not able to find how to assign those notification contents (attribute values in this case) as the value of the parameters of my web service, which is the delivery channel subscribed to the notifications.

     

    0434.notification_5F00_subscription.PNG

     

    In the image you can see what I am trying to do: set these value fields which are the parameters of the web service programmatically.

     

    Hope you can help me.

     

    Thanks in advance.

     

    Ernesto,

     

    Getting the information about the triggered notification is a standard task and I can point you to examples on how to do this programmatically. Calling the web service methods and passing on these values would then depend on the syntax of your web service. Here is an example from the booklet of the PI Application Development course (you can download from vCampus Training Center). Imagine you want to deliver the content of the notification through an XML file as below:

     

    <Notification>

     

        <NotificationName>...</NotificationName>

     

        <NotificationDescription>...</NotificationDescription>

     

        <NotificationState>...</NotificationState>

     

        <StartTime>... </StartTime>

     

        <EndTime>...</EndTime>

     

    </Notification>

     

    The exercise in chapter 9 of the booklet I mentioned above walks you through creating such a delivery channel. You would then need to call your web service with these pieces of metadata instead of putting them in an XML file.

     

     

     

     

     

     

     

    Hi Ernesto,

     

    You need to set the ConfigString property on the AFNotificationContact object. However the format for WebService is somewhat complex and there isn't a public API for building it. I would start by configuring the endpoint the way I needed in the UI and then exporting the notification to xml. The config string for the notification contact will be in there and you can then copy that and tweak it in code.

     

    If you had a web service with a single parameter (parameter1) of type String that you wanted to send an attribute value to, the config string will look something like this:

     

    WebServiceMethodParameters=<Parameters>

     

    <parameter1 ParameterType="System.String" DisplayName="\\myafserver\database\element|attribute" ContentType="OSIsoft.AF.Notification.AFNotificationContent">{content id}</parameter1>

     

    </Parameters>

     

    Where {content id} is the ID of the attribute value content item on the notification.

     

    I hope this helps get you started.

     

    Mike

     

    Thanks a lot Michael!

     

    That was exactly what I was looking for. It has worked perfectly. I was messing my head and looping over more difficult things when the solution was so easy.

     

    Greetings.

     

    Hi again. I don't open a new thread due to my question is directly related with this one I posted some weeks ago.

     

    I have set the ConfigString property like this:

     

    contact.ConfigString = string.Format("WebServiceMethod=CallAFtoSAPWebService;WebServiceMethodParameters=<Parameters>"

     

    + "<ptomedida ParameterType=\"System.String\" DisplayName=\"{0}\" ContentType=\"OSIsoft.AF.Notification.AFNotificationContent\">{1}</ptomedida>"

     

    + "<value ParameterType=\"System.String\" DisplayName=\"{2}\" ContentType=\"OSIsoft.AF.Notification.AFNotificationContent\">{3}</value>"

     

    + "</Parameters>;WebServiceName=UpdateMeasurementPointMiddleware;WebServiceURL=10.1.3.19/.../UpdateMeasurementPointMiddleware.asmx

     

    , pathAttPtoMedida, idAttPtoMedida, pathAttValue, idAttValue);

     

     

     

    The notification works fine, and it triggers correctly. But when I check the parameters in my web service, both of them are the empty string. Is anything I am missing? I have checked the notifications panel in the PI System Explorer and seems to be ok.

     

    @Ernesto: The logic you use will work fine. Although, make sure to have your attribute declaration within your XML element well formed. In your example, the configstring property will receive the value below. You can notice there are no white spaces between the DisplayName and ContentType attributes. This might cause a problem.

     

    WebServiceMethod=CallAFtoSAPWebService;WebServiceMethodParameters=v1v2 ;WebServiceName=UpdateMeasurementPointMiddleware;WebServiceURL=http://10.1.3.19/UpdateMeasurementPointWS/UpdateMeasurementPointMiddleware.asmx?op=CallAFtoSAPWebService
    

     

     

    Also, don't forget to call the contact.CheckIn() method after the modification to persist the information in the PI AF Server.

     

    Let me know if that worked.

     

    Hi,

     

    Thanks you all for such great post.

     

    Here I have query  related to this topic. I am trying develop a WinForm where I want to create the Notifications and Contacts programatically( using Email and Web Service Deliver Point) . Here I was able to create the Notifications with Email Delivery Point and its working with no issues.

     

    And I was also able to create Notification with Web Service End Point , but I am unable figure it out how i can "Add Parameter And Value" (as shown below )programatically.

     

    3857.Add-A-Parameter-And-Value.JPG

     

    Here For_WS_8 is the notification and WS_8 is Webservice End Point.

     

    Please help me to find the answer.

     

    Thanks

     

    Vijay

     

    @Vijay: The form you are looking is the ContentParameterForm from OSIsoft.AN.UI namespace. I have added an excerpt of code showing this use.

     

    OSIsoft.AN.UI.ContentParameterForm CPForm = new OSIsoft.AN.UI.ContentParameterForm(MyNotification);
    CPForm.Show();
    
    //As an example to create a configuration string...
    ConfigString = string.Format("{0}={1};", CPForm.ParameterName, CPForm.ParameterValueName);
    

    Let me know if that helped.

     

    Hi Mathieu,
    Thanks for your reply.

     

    After going through above posts again..I found that we can acheive this through "ConfigString"

     

    PFB the code which helped me to acheive this.

     

    contact.ConfigString = string.Format("WebServiceMethod=Noti;WebServiceMethodParameters=<Parameters><Name ParameterType=\"System.String\" DisplayName=\"Name\" ContentType=\"System.String\"></Name><Description ParameterType=\"System.String\" DisplayName=\"Description\" ContentType=\"System.String\"></Description><ID ParameterType=\"System.String\" DisplayName=\"Notification ID\" ContentType=\"System.String\"></ID></Parameters>;WebServiceName=Service;WebServiceURL=http://localhost/Service/Service.asmx?op=Noti");

     

    Thanks

     

    Vijay

     

    I could not find OSIsoft.AN.UI.ContentParameterForm  anywhere.  Is the namespace updated?

     

    It is in the OSIsoft.PIAnalytics.Common assembly, which is part of the PI Notifications Client. It is registered in the GAC and located in C:\Program Files (x86)\PIPC\Analytics\PublicAssemblies

     

    There is a case 668514 related this Add Parameter and Value dialog.

    Question is following.

    Is the dialog box available in the AFSDK UI namespace?

     

    I want to share my answer with forum.

     

    I believe you need to use ANSDK for displaying this Add Parameter and Value dialog.

    I know AFSDK contains OSIsoft.AF.Notification namespace.

    So we can get Notification object by AFSDK.

    Although AFSDK for UI (OSIsoft.AF.UI namespace) does not contain the dialog.

     

    If the machine contains PI Notification, There are ANSDK dll files.

    %PIHOME%\Analytics\PublicAssemblies\OSIsoft.PIAnalytics.SDK.dll and OSIsoft.PIAnalytics.Common.dll

     

    From Visual Studio, you can add these dlls as references.

    Also add using.

    using OSIsoft.AN.UI;

    using OSIsoft.AF.Notification;

    using OSIsoft.AF.Analysis;

    (I used AFSDK to get Notification)

    I tried following code and it worked.

    AFNamedCollectionList<AFNotification> list;
    list = AFNotification.FindNotifications(myAFDatabase, "*", AFSearchField.Name, AFSortField.Name, AFSortOrder.Ascending, 100);
    AFNotification MyNotification= list[0];
    ContentParameterForm CPForm = new ContentParameterForm(MyNotification);
    CPForm.ShowDialog();
    String ConfigString = CPForm.ParameterName + CPForm.ParameterValueName;
    MessageBox.Show(ConfigString);
    

    I can see the dialog

    Message Box shows correctly.

    For displaying Message box, I needed to change CPForm.Show() to CPForm.ShowDialog();

     

    Thanks!  That did the trick!

     

    该文档由下列讨论生成:PI Notification and Web Service