</<pre lang="c#"> namespace API.Core.Da { [ServiceContract] public interface IServers { Opc.Server[] GetRemoteServers(string host); } [DataContract] public class Servers : MarshalByRefObject, IServers { // A // This method the IDE tooltip says that an object reference is required for the non static field, method, property GetRemoteServers [OperationContract] public Opc.Server[] GetRemoteServers(string host) { IDiscovery discovery = new OpcCom.ServerEnumerator(); //Get all OPC DA servers of version 2.0 of machine "MyMachine" Opc.Server[] hostservers = discovery.GetAvailableServers(Specification.COM_DA_20, host, null); return hostservers; } // A // This method the IDE tooltip says that an object reference is required for the non static field, method, property CreateServer [OperationContract] public Opc.Da.Server CreateServer(Opc.URL url, System.Net.NetworkCredential credentials) { Opc.Da.Server client = null ; OpcCom.Factory fact = new OpcCom.Factory(); client = new Opc.Da.Server(fact, url ); return client; } // B // This method the IDE tooltip does not say it requires any object reference it just shows the tooltip that a good method should. [OperationContract] public Opc.Da.Server CreateServer(string OpcUrl, OpcCom.Factory factory, System.Net.NetworkCredential Credential) { Opc.URL Url = new Opc.URL(OpcUrl); Opc.Da.Server client = new Opc.Da.Server(factory, null ); client.Connect(Url, new Opc.ConnectData(Credential)); return client; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)