3 Replies Latest reply on Sep 28, 2012 12:51 PM by mhamel

    Easy test script for PI Web Services

    DavidMFairchild

      This question is regarding Mathieu Hamel's blog post of the same name.  A link to the code is here.

       

      This script works nicely for me when run on the web server, but fails when I run it on a workstation.

       

      The error I am getting is "Exception calling 'UploadString' ... the remote server returned an error: (404) Not Found."  Indicating that the web server could not find the URL expressed in $EndPoint.  $EndPoint is written to the console.  If I copy that and paste it into the address on IE I get the standard "PITimeSeriesService Service" response as expected.  I even tried launching IE from the PowerShell console to be sure there wasn't some user conflict.  But I still get the same error.

       

      So, clearly, I can get to the URL.  So, what is the problem?

       

      I noticed that, in the code, that $_XMLMessageTemplate doesn't provide a location for the PIArcMannerRetrievalType and NumValues.  But you do provide these two values in the String.Format() statement.  However, this does not prevent the script from running on the Web Server.  I believe it uses the default retrieval type (Compressed?).  Just for the heck of it, I added them to the code, but I still get the same error.

       

      Here is a copy of my web.config file.  As  you can see I am using BasicHTTP until I can get the server to work.

       
      <?xml version="1.0" encoding="UTF-8"?>
      
      <configuration>
      
        <configSections>
      
          <section name="PIWebServiceSettings" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" requirePermission="false" />
      
          <section name="pidsSettings" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" requirePermission="false" />
      
        </configSections>
      
        <PIWebServiceSettings>
      
          <add key="AllowCalculations" value="true" />
      
          <add key="AllowDataEntry" value="true" />
      
          <add key="FloatPrecision" value="DisplayDigits" />
      
          <add key="UpdatePurgeInterval" value="5" />
      
        </PIWebServiceSettings>
      
        <pidsSettings>
      
          <add key="PIinstrumentationConfigFile" value="I:\XxxPIWebservices\PIWebServices\PIInstrumentation.config" />
      
        </pidsSettings>
      
        <appSettings>
      
        </appSettings>
      
        <connectionStrings />
      
        <system.web>
      
          <compilation debug="false" targetFramework="4.0">
      
            <assemblies>
      
              <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
      
              <add assembly="System.Configuration.Install, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
      
              <add assembly="System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
      
              <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
      
              <add assembly="OSIsoft.PIDataServices.DataAccess, Version=3.2.0.0, Culture=neutral, PublicKeyToken=53b77d1d3d7a979b" />
      
              <add assembly="OSIsoft.PIDataServices.Common, Version=3.2.0.0, Culture=neutral, PublicKeyToken=53b77d1d3d7a979b" />
      
              <add assembly="OSIsoft.PIDataServices.Configuration, Version=3.2.0.0, Culture=neutral, PublicKeyToken=53b77d1d3d7a979b" />
      
              <add assembly="OSIsoft.PIDataServices.DataService, Version=3.2.0.0, Culture=neutral, PublicKeyToken=53b77d1d3d7a979b" />
      
              <add assembly="OSIsoft.PIInstrumentation, Version=3.2.0.0, Culture=neutral, PublicKeyToken=53b77d1d3d7a979b" />
      
              <add assembly="OSIsoft.PIInstrumentation.Listeners, Version=3.2.0.0, Culture=neutral, PublicKeyToken=53b77d1d3d7a979b" />
      
            </assemblies>
      
          </compilation>
      
          <authentication mode="Windows" />
      
          <identity impersonate="false" />
      
          <customErrors mode="Off" defaultRedirect="GenericErrorPage.htm">
      
            <error statusCode="403" redirect="NoAccess.htm" />
      
            <error statusCode="404" redirect="FileNotFound.htm" />
      
          </customErrors>
      
          <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
      
        </system.web>
      
        <system.serviceModel>
      
          <serviceHostingEnvironment aspNetCompatibilityEnabled="false" />
      
           <bindings>
      
              <basicHttpBinding>
      
                 <binding name="basicBinding" />
      
              </basicHttpBinding>
      
              <mexHttpBinding>
      
                 <binding name="mexBinding" />
      
              </mexHttpBinding>
      
           </bindings>
      
          <services>
      
            <service behaviorConfiguration="PIDataService.Service1Behavior"
      
              name="PIWebServices.PIDataService.PITimeSeriesSvcImpl">
      
              <endpoint address="mex" binding="mexHttpBinding" name="mexBinding"
      
                contract="IMetadataExchange" />
      
              <endpoint binding="basicHttpBinding" bindingConfiguration="basicBinding"
      
                name="BasicEndpoint" bindingNamespace="
      http://xml.osisoft.com/services/PIDataService"
      
                contract="PIWebService.PIDataService.IPITimeSeries">
      
                <identity>
      
                  <servicePrincipalName value="XXXXXXX/steas" />
      
                </identity>
      
              </endpoint>
      
            </service>
      
          </services>
      
          <behaviors>
      
            <serviceBehaviors>
      
              <behavior name="PIDataService.Service1Behavior">
      
                <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      
                <serviceDebug includeExceptionDetailInFaults="true" />
      
                <serviceCredentials>
      
                  <windowsAuthentication includeWindowsGroups="true" allowAnonymousLogons="false" />
      
                  <issuedTokenAuthentication allowUntrustedRsaIssuers="true" />
      
                </serviceCredentials>
      
                <serviceAuthorization principalPermissionMode="UseWindowsGroups"
      
                  impersonateCallerForAllOperations="false" />
      
              </behavior>
      
            </serviceBehaviors>
      
          </behaviors>
      
        </system.serviceModel>
      
      </configuration>
      
      
      
      
       
      
      P.S. Steve, the "Insert Code" functionality of this forum didn't seem to work for me.  It appeared to insert empty lines for the code, but there was not visible text either in the wysiwyg display or the preview.
      
        • Re: Easy test script for PI Web Services
          mhamel

          @David: If your virtual application is configured to only allow Windows Authentication and not anonymous, this will prevent to access the .svc end-point outside the machine. You can easily test this behavior by enabling the Anonymous Authentication option on the PIWebServices Virtual Application under the Web Server (IIS).

           

          If you want to keep this setting permanently you will need to configure/expose an anonymous access to the .svc file, in other word your end-point. In this particular case, you will need to allow an anonmyous access to the PITimeSeries.svc file. This Microsoft TechNet article shows you how to do this.

           

          P.S. For those interested to see the web.config file involved, you can find an attached version here.

           

          The PIArcMannerRetrievalType and NumValues parameters from the PIArcManner "object" were not defined in my previous script. This will result in taking the default values. I have updated my script to reflect these two parameters. You can find it here.

            • Re: Easy test script for PI Web Services
              DavidMFairchild

              Matt,

               

              I am trying to figure out what you are talking about here.  The technet article talks about enabling anonymous access but calls for things (like an "Enable anonymous access" check box) that don't appear to be available in IIS 7.5.

               

              I did add the user "Everyone" to the PiTimeseries.svc file and give it read/execute access.  But that didn't help.  There is an Authentication mode under System.Web which was set to Windows, I changed it to None (there isn't an "Anonymous" option according to <a ref="msdn.microsoft.com/.../system.web.configuration.authenticationmode.aspx" title="MSDN">MSDN</a>.  This also did not allow the Powershell script to work.  The web page "PITimeSeriesService Service" web page still works though.

               

              Can you be more specific about which settings need to be changed to get the script to work or provide a link to an article that will explain the setting changes required to set up anonymous authentication?

               

              Thanks,

               

              Dave

                • Re: Easy test script for PI Web Services
                  mhamel

                  @David: Let me restart from a different angle. This PowerShell script requires that the endpoint is configured with basic binding and no security. By default, during the installation/configuration of a new virtual application within the Microsoft Web Server (aka IIS), two authentication schemes are enabled: Anonymous and Windows Integrated. To tighten the security, if you have remove the anonymous authentication method this will prevent the script to work. What I described in my previous post was on how to activate anonymous access on the .svc file and maintaining a non-anonymous access on other components.

                   

                  The anonymous access you need to configure is within IIS and not on the file itself. Maybe you can try to activate anonymous access for the whole application. I have added a link to this Microsoft article on how to do this with IIS 7/7.5.

                   

                  Some other questions, when you say that the web page (PITimeSeries service) works, do you mean from the Web Server or from an external machine? I would recommend you try to access it from a different machine to validate your endpoint is accessible.