3 Replies Latest reply on Jun 18, 2015 7:13 PM by bshang

    C# Restful Service - How to Query PI


      I'm trying to write a restful service that is in C# and I'm looking to query PI with queries like below.  I'm not finding any code snippets on how to accomplish then.  Does anybody have experience doing this?  For the particular query below I'm trying to get back the stale count of a interface based on the point source and stale range I have set.


      SELECT count('a') as Stalecount


      FROM piarchive..pisnapshot


      WHERE tag IN (


      SELECT tag FROM pipoint..classic


      WHERE pointsource = 'XYZ'


      and location1=5 and scan=1)


      AND ((DATE('*') - time) BETWEEN RELDATE('30h') AND RELDATE('365d') OR status <> 0)


      AND tag not like '*sy.st*'

        • Re: C# Restful Service - How to Query PI

          Hi Jorge,


          Are you looking to create your own Web API service and expose SQL-like functionality via PI OLEDB? Something like client-->custom Web API-->PI OLEDB-->PI Data Archive? Just want to make sure as I don't see anything wrong with the query itself. What is driving the requirement to create your own RESTful service? This information would help us determine the best way forward in this case (e.g. PI ODBC via HTTPS may offer similar functionality).

            • Re: C# Restful Service - How to Query PI

              I have a web api service that does several calls to PI already and this is another piece that I'm adding to it that will allow me to call it on a scheduled basis.    The query is fine like you said but I just want to find a way to query PI from C# in my restful web service.  I would like to be able to query PI with the query above and then write the results back to a PI tag.