10 Replies Latest reply on Mar 20, 2015 3:49 PM by rsun

    Question for PI Web API: C# Client


      Hi all,


      Referring to PI Web API: C# Client , I try to follow step by step but fail at the point which can view the

      "link" contents similar as below (capture from  PI Web API: C# Client )




      However, I can get similar information by directly typing the hyperlink https://<piwebapiserver>/piwebapi/assetdatabases?paths=<AFServerDB>.

      in web browser. (It downloads a text file "assetdatabases.json" and when open it, similar information as above can find.


      May anyone can help?


      My development environment configuration:

      - Visual Studio 2013 Professional (Console Project Target Framework: 4.5.2)

      - Json.Net 6.0.8 (NewtonsoftJson)



        • Re: Question for PI Web API: C# Client

          Hi Paul,


          Did you fail to see the contents of "links", or fail to see everything under dynamic view?

          When you step over the MakeRequest(databaseUrl) method in main and look at your locals window, what did you see under database > Dynamic View? As well as database > Dynamic View > Links?

          Are you running your web browser and visual studio under the same user? What form of authentication is supported on your PI Web API server (look at https://<web_api_server>/piwebapi/system/configuration)?



          2015-03-02 09_44_20-PIWebAPITest (Debugging) - Microsoft Visual Studio.png

          2015-03-02 09_47_34-PIWebAPITest (Debugging) - Microsoft Visual Studio.png

            • Re: Question for PI Web API: C# Client

              Hi Daphne,


              Thank you for your prompt reply.


              Today I tried to run my project code again but it fail to arrive "Dynamic View" as mentioned before.

              It stops at "WebResponse response = await request.GetResponseAsync();".

              The error is attached as below:



              I have checked the server certificates where the PIWebAPI installed:

              (Those marked yellow area are the local server name only.)


              My answers for other questions:

              - Yesterday I can see something (but not links) in dynamic view. (If I am able to see it later, I will upload it for reference.)

              - The authentication is Kerberos.

              - Both running the console program and typing the piwebapi hyperlink is using my domain account. I can browse the AF elements \\<AFServer>\<AFDatabase> in PI System Explorer by my domain account.


              Thank you!

                • Re: Question for PI Web API: C# Client

                  This can happen in Visual Studio environments when using a self-signed certificate. See, for example, the second response in c# - Could not establish trust relationship for SSL/TLS secure channel -- SOAP - Stack Overflow


                  As mentioned in the post, to trust all certificates, you can use

                  System.Net.ServicePointManager.ServerCertificateValidationCallback =
                  ((sender, certificate, chain, sslPolicyErrors) => true);


                  before making the PI Web API call. This is generally safe if you are aware or in control of the web server. Can you try the method above and let us know how it goes?

                  1 of 1 people found this helpful
                  • Re: Question for PI Web API: C# Client

                    Hi Paul,


                    Which certificate are you using for PI Web API? Make sure you are using the self-signed certificate instead of the WMSvc one. One way to check is opening up a browser and navigate to https://<PI web API server>/piwebapi and click on the certificate icon next to the URL for more information.


                    You mentioned that you were able to navigate the AF structure on the browser; however, at initial connection, did you get a certificate not trusted warning from the browser? If this is the case, you may also get around the issue by installing the self-signed certificate into the Windows certificate store (links: here and here).

                      • Re: Question for PI Web API: C# Client

                        Hi all,


                        Yesterday I uninstalled PI Web API 2014 R2 Update 1 ( and installed PI Web API 2015 CTP ( for trial.

                        In my first installation I try to not install the "OSIsoft self-signed certificate" but the installation halted.

                        During second installation, the "OSIsoft self-signed certificate" is installed and the whole installation process succeeded.


                        May I know is it possible to change the certificate for PI Web API using (after installation) from "OSIsoft self-signed certificate" to the one issued by "Enterprise Sub CA 2" in my case?

                        The reason is I am not able to install the "OSIsoft" certificate in my local development computer. (By either MMC - Add/Remove Snap-in or install in web browser.)




                        Below is the screen dump that show currently "OSIsoft" certificate is using:



                          • Re: Question for PI Web API: C# Client

                            Hi Paul,


                            Yes, you can change the PI Web API certificate after installation. Go to Control Panel > Programs and Features, right click on the PI Web API installation and select "Change". Go through the change option and you can change your certificate at the certificate step.

                            Ah.. I see that you do get a certificate error with your browser. Make sure you are using the FQDN for the PI Web API computer that you are connecting to (or whichever hostname specified on the certificate), both on the browser as well as in code. You mentioned that you were not able to install the self-signed certificate on the local computer, did you get an error doing so?

                              • Re: Question for PI Web API: C# Client

                                Hi Daphne,


                                I have changed the certificate following your instruction and succeed. Thank you for that. I mark your answer as correct answer.


                                Finally I can view the "Dynamic View":


                                P.S.: I have also updated the PI Web API version from 2015 CTP ( to 2015 (


                      • Re: Question for PI Web API: C# Client

                        Although we don't encourage using anonymous, but if you hit a 401 error


                        {"The remote server returned an error: (401) Unauthorized."} in your code.


                        we can change the authentifcationMethods from 0 Kerberos to 0 anonymous and the code should be running.