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)?
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.
1 of 1 people found this helpful
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
((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?
Thanks Barry's feedback!
Your reply is about SOAP call but it seems PI Web API use Restful style call (unlike PI Web Services which use SOAP).
Your message also inspired me to see if it is able to trust all SSL connection in System.Net.WebRequest (according from PI Web API: C# Client). I found a link below and the result seems negative
(Currently I am not allowed to use "Powershell" way to get this done):
Thank you Barry anyway!
Although the article is about SOAP, it applies to RESTful calls as well. I actually encountered the same error and adding the line I suggested fixed the issue for me. To use it, you'll also have to bring the following namespaces into scope.
Is this something you can try or did it not work for you?
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).
Yesterday I uninstalled PI Web API 2014 R2 Update 1 (126.96.36.199) and installed PI Web API 2015 CTP (188.8.131.52) 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:
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?