none
WCF Client missing some functions from service RRS feed

  • Question

  • I  made a service but I am missing a function  from the client side...

    I did a server reference and I see all but one function and i do not see my constructor..

    what should i do ?

    Friday, January 10, 2014 4:07 AM

All replies

  • Hi,

    May be I guess you Missed to annotate the Function with OperationContract attribute. That's why the function is missing. 

    Out of the box WCF will create a default constructor of its own and you also can't use parameterised constructors unless you do some extra work like this http://stackoverflow.com/questions/2454850/how-do-i-pass-values-to-the-constructor-on-my-wcf-service/2455039#2455039 So Constructors are basically not needed. If you want to initialize some values initialize globally.


    srithar

    Friday, January 10, 2014 5:11 AM
  • no I have it...

    I have tried to deleted the .dll file 

    from both the class project and the Host project and rebuilt them

    I have tried remove the server reference and redoing it and that function is still not coming uP. once you build a service is there a way to go back and add a new function ? 

    Friday, January 10, 2014 1:43 PM
  • here is my code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    using Opc.Hda;
    using Opc;
    using System.Data;
    using System.Runtime.Serialization;


    namespace PHDhelper
    {
        [ServiceContract]
        public interface IPHDhelper
        {

    [OperationContract]
    void PHDhelper1(String hostName, string progId);
    [OperationContract]
    int connect();
     [OperationContract]
    List<string> GetAggregates();
    [OperationContract]
    void Disconnent();
    [OperationContract]
    void AddItem( string itemName);
    [OperationContract]
    DataTable ReadRaw(DateTime startTime, DateTime endTime, int maxValues, bool inclubeBounds);
    [OperationContract]
     int GetAggregateId(string aggregate);
        }

        public class PHDhelp
        {




        }
        public class PHDhelper : IPHDhelper
        {
           [DataMember]
            private Opc.Hda.Server _hdaServer;
             [DataMember]
            private string _prgId;
             [DataMember]
            private string _hostName;

             [DataMember]
            public string PrgId
            {
                get { return _prgId; }
                set { _prgId = value; }
            }

             [DataMember]
            public string HostName
            {
                get { return _hostName; }
                set { _hostName = value; }
            }
             public PHDhelper()
             {

             }

            public void PHDhelper1(String hostName, string progId)
            {
                this._hostName = hostName;
                this._prgId = progId;

                string Url = string.Format("opchda://{0}/{1}", _hostName, _prgId);
                try
                {
                    this._hdaServer = new Opc.Hda.Server(new OpcCom.Factory(), new Opc.URL(Url));
                }
                catch (Exception e)
                {
                    throw;
                }
            }


            public int connect()
            {
                try
                {

                    if (_hdaServer != null)
                        _hdaServer.Connect();
                    return 2;
                }
                catch (Exception e)
                {
                    return 3;
                    throw;
                }
            }

            public List<string> GetAggregates()
            {
                List<string> list = new List<string>();
                Aggregate[] aggregates = _hdaServer.GetAggregates();

                foreach (Aggregate aggregate in aggregates)
                {
                    list.Add(aggregate.Name);

                }
                return list;
            }

            public void Disconnent()
            {
                if (_hdaServer != null && _hdaServer.IsConnected == true)
                {

                    _hdaServer.Disconnect();
                    _hdaServer.Dispose();

                }
            }

            public void AddItem(string itemName)
            {
                if (_hdaServer != null)
                {

                    ItemIdentifier itemIdentifier = new ItemIdentifier(itemName);
                    ItemIdentifier[] items = { itemIdentifier };
                    IdentifiedResult[] addItemResults = _hdaServer.CreateItems(items);
                    IdentifiedResult[] validateItemResults = _hdaServer.ValidateItems(items);


                }
            }

            public DataTable ReadRaw(DateTime startTime, DateTime endTime, int maxValues, bool inclubeBounds)
            {
                Opc.Hda.Time hdaStartTime = new Time(startTime);
                Opc.Hda.Time hdaEndTime = new Time(endTime);
                DataTable dataTable = new DataTable("Data");
                DataColumn timestamp = new DataColumn("TimeStamp");
                DataColumn value = new DataColumn("Value");
                DataColumn quality = new DataColumn("Quality");
                dataTable.Columns.Add(timestamp);
                dataTable.Columns.Add(value);
                dataTable.Columns.Add(quality);
                ItemIdentifierCollection itemIdentifierCollection = null;
                ItemIdentifier[] items = null;
                int index = 0;
                if (_hdaServer.Items.Count != 0)
                {
                    itemIdentifierCollection = _hdaServer.Items;
                    items = new ItemIdentifier[itemIdentifierCollection.Count];
                }

                Opc.Hda.Trend group = new Opc.Hda.Trend(_hdaServer);

                foreach (ItemIdentifier itemIdentifier in itemIdentifierCollection)
                {
                    items[index] = itemIdentifier;
                    Opc.IdentifiedResult[] results = group.Server.ValidateItems(new Opc.ItemIdentifier[] { itemIdentifier });
                    group.AddItem(itemIdentifier);

                    index++;
                }

                try
                {

                    group.Name = group.Server.Url.HostName + Guid.NewGuid().ToString();
                    group.EndTime = new Opc.Hda.Time(endTime);
                    group.StartTime = new Opc.Hda.Time(startTime);
                    TimeSpan span = endTime.Subtract(startTime);
                    int Calcinterval = ((int)span.TotalSeconds)/ 100;
                    group.ResampleInterval = (decimal)Calcinterval;
                    group.AggregateID = Opc.Hda.AggregateID.INTERPOLATIVE;// Opc.Hda.AggregateID.INTERPOLATIVE;
                    group.MaxValues = 62;
                    ItemValueCollection[] values = group.ReadRaw();
                    //   ItemValueCollection[] values = _hdaServer.ReadRaw(hdaStartTime, hdaEndTime, maxValues, includeBounds, items);
                    foreach (ItemValueCollection itemValueCollection in values)
                    {
                        foreach (ItemValue itemValue in itemValueCollection)
                        {
                            DataRow dataRow = dataTable.NewRow();
                            dataRow["Timestamp"] = itemValue.Timestamp;
                            dataRow["Value"] = itemValue.Value;
                            dataRow["Quality"] = itemValue.Quality;
                            dataTable.Rows.Add(dataRow);
                        }
                    }
                }
                catch (Exception e)
                {
                    throw;
                }

                return dataTable;

            }

            public int GetAggregateId(string aggregate)
            {
                Aggregate[] aggregates = _hdaServer.GetAggregates();

                int aggregateId = 1;
                for (int index = 0; index < aggregates.Length; index++)
                {
                    if (aggregates[index].Name == aggregate)
                    {
                        aggregateId = index + 1;
                        return aggregateId;
                    }

                }

                return aggregateId;
            }
        }
    }

    Friday, January 10, 2014 1:51 PM