peter.cunningham

Posting data to PI Web Service

Discussion created by peter.cunningham on Nov 8, 2012
Latest reply on Nov 16, 2012 by spilon
        Imports System
        Imports System.ServiceModel
        Imports System.ServiceModel.BasicHttpBinding

        Dim tvTimedValues(0) As TimedValue
        tvTimedValues(0) = New TimedValue
        tvTimedValues(0).Path = "PI\\BK9FSROSIDEV1\TESTTAG1"
        tvTimedValues(0).Time = Now()
        tvTimedValues(0).Value = 123.456
        tvTimedValues(0).Status = 0
        tvTimedValues(0).PctGood = 0
        tvTimedValues(0).PctGoodSpecified = False

        Dim tsTimeSeries(0) As TimeSeries
        tsTimeSeries(0) = New TimeSeries
        tsTimeSeries(0).TimedValues = tvTimedValues

        'Set up the binding element to match the app.config settings
        Dim binBinding As System.ServiceModel.WSHttpBinding = New System.ServiceModel.WSHttpBinding
        binBinding.Name = "TimeSeriesEndpoint"
        binBinding.CloseTimeout = TimeSpan.FromMinutes(1)
        binBinding.OpenTimeout = TimeSpan.FromMinutes(1)
        binBinding.ReceiveTimeout = TimeSpan.FromMinutes(10)
        binBinding.SendTimeout = TimeSpan.FromMinutes(1)
        binBinding.BypassProxyOnLocal = False
        binBinding.TransactionFlow = False
        binBinding.HostNameComparisonMode = System.ServiceModel.HostNameComparisonMode.StrongWildcard
        binBinding.MaxBufferPoolSize = 524288
        binBinding.MaxReceivedMessageSize = 65536
        binBinding.MessageEncoding = WSMessageEncoding.Text
        binBinding.TextEncoding = System.Text.Encoding.UTF8
        binBinding.UseDefaultWebProxy = True
        binBinding.AllowCookies = False

        binBinding.ReaderQuotas.MaxDepth = 32
        binBinding.ReaderQuotas.MaxStringContentLength = 8192
        binBinding.ReaderQuotas.MaxArrayLength = 16384
        binBinding.ReaderQuotas.MaxBytesPerRead = 4096
        binBinding.ReaderQuotas.MaxNameTableCharCount = 16384

        binBinding.ReliableSession.Ordered = True
        binBinding.ReliableSession.InactivityTimeout = TimeSpan.FromMinutes(10)
        binBinding.ReliableSession.Enabled = False

        binBinding.Security.Mode = BasicHttpSecurityMode.Message
        binBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows
        binBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None
        binBinding.Security.Transport.Realm = ""
        binBinding.Security.Message.ClientCredentialType = MessageCredentialType.Windows
        binBinding.Security.Message.NegotiateServiceCredential = "true"
        binBinding.Security.Message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default
        binBinding.Security.Message.EstablishSecurityContext = "true"

        'Define the endpoint address'
        Dim endEndPoint As System.ServiceModel.EndpointAddress = New System.ServiceModel.EndpointAddress("http://TESTSERVER1/PIWebServices/PITimeSeries.svc")

        Dim client As PITimeSeriesClient = New PITimeSeriesClient(binBinding, endEndPoint)
        client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation
        
        Dim tsTimeSeriesResult(0) As TimeSeries
        tsTimeSeriesResult(0) = New TimeSeries
        tsTimeSeriesResult(0) = client.InsertPIData(tsTimeSeries, InsertPIDataDuplicateSwitch.ReplaceDuplicate)

        client.Close()
 
'NOTE: For PITimeSeriesClient Class, run svcutil.exe http://TESTSERVER1/PIWebServices/PITimeSeries.svc?wsdl to generate PITimeSeriesService.vb and add to the project

 

 

Outcomes