eweewee

Error accessing PI Webservice (C#.Net)

Discussion created by eweewee on Jan 23, 2012
Latest reply on May 31, 2012 by spilon

Hi All,

 

I have writen a sample code to acces PI Webservices but receive an error when I run the code. Can you help me with this?

 

As I run the code on a different computer I got an authentication error (see attachment error1).

 

When running the code on the same computer where the WebService is installed I got another error message (see attachment error1). my piserver name is pi.magion.nl.

 

5381.error1.png

 

 7558.error2.png

 

sample code : 

 

 

 
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

PITimeSeriesRef.PITimeSeriesClient proxy = new PITimeSeriesRef.PITimeSeriesClient("BasicEndpoint");



// set up for a single request -- the WS supports multiple requests returning multiple time series

PITimeSeriesRef.PIArcDataRequest[] reqs = new PITimeSeriesRef.PIArcDataRequest[1];

PITimeSeriesRef.PIArcDataRequest req = new PITimeSeriesRef.PIArcDataRequest();

// set the request time range from the controls

PITimeSeriesRef.TimeRange tr = new PITimeSeriesRef.TimeRange();

tr.Start = "-2h";

tr.End = "*";

req.TimeRange = tr;

// set the manner using some assumptions

PITimeSeriesRef.PIArcManner arcmnr = new PITimeSeriesRef.PIArcManner();

arcmnr.Boundaries = PITimeSeriesRef.PIArcMannerBoundaries.Inside;

arcmnr.NumValues = 100;

arcmnr.RetrievalType = PITimeSeriesRef.PIArcMannerRetrievalType.Compressed;

arcmnr.Updates = false;

// arcmnr.Filter = "sinusoid";

req.PIArcManner = arcmnr;

// set the path

req.Path = "pi://pi.magion.nl/sinusoid";

reqs[0] = req;

try

{

Console.WriteLine(proxy.ClientCredentials.UserName);

Console.WriteLine(req.Path);

// call the web service through the proxy

PITimeSeriesRef.TimeSeries[] rts = proxy.GetPIArchiveData(reqs);

if (rts.Length >= 1)

{

// extract the (expected) single time series

PITimeSeriesRef.TimeSeries ts = rts[0];

if (ts.Error != 0)

{

Console.WriteLine("timeseries error " + ts.ErrDesc);

}

foreach(PITimeSeriesRef.TimedValue value in ts.TimedValues)

{

string line = "";

if (value.Value != null && value.Time != null)

{

line = value.Value + "\t\t" + value.Time.ToString("yyyy'-'MM'-'dd'T'HH':'ss'.'FK'");

Console.WriteLine(line);





}

else

{

Console.WriteLine("no values found");

}

}

}

}

catch (Exception ex)

{

MessageBox.Show(ex.Message);

Console.WriteLine("cannot retrieve data " + ex.Message);





}

finally

{

if (proxy.State == System.ServiceModel.CommunicationState.Opened)

{

proxy.Close();

}



}







}

}

}

 

 

 

 

 

Outcomes