public static void Main(string[] args) { //// To simple use the configuration stored within the XML configuration file //// beside the client application you just need to load the configuration file as the //// following code does demonstrate. //// By default it is not necessary to explicitly configure an OPC UA client. But in case //// of advanced and productive scenarios you will have to. // There are different ways to load the client configuration. OpcApplicationConfiguration configuration = null; // 1st Way: Load client config using a file path. configuration = OpcApplicationConfiguration.LoadClientConfigFile( Path.Combine(Environment.CurrentDirectory, "ClientConfig.xml")); // 2nd Way: Load client config specified in a specific section of your App.config. configuration = OpcApplicationConfiguration.LoadClientConfig("Opc.UaFx.Client"); // If the client uris domain name does not match localhost just replace it // e.g. with the IP address or name of the client machine. var client = new OpcClient("opc.tcp://localhost:4840/SampleClient"); // To take use of the loaded client configuration, just set it on the client instance. client.Configuration = configuration; client.Connect(); client.Disconnect(); // In case you are using the OpcClientApplication class, you can explicitly trigger // loading a configuration file using the App.config as the following code does // demonstrate. var app = new OpcClientApplication("opc.tcp://localhost:4840/SampleClient"); app.LoadConfiguration(); // Alternatively you can assign the manually loaded client configuration on the client // instance used by the application instance, as the following code does demonstrate. app.Client.Configuration = configuration; app.Run(); }
public static void Main(string[] args) { //// To simple use the in code configuration you just need to configure your client //// instance using the Configuration property of it. //// By default it is not necessary to explicitly configure an OPC UA client. But in case //// of advanced and productive scenarios you will have to. // If the server domain name does not match localhost just replace it // e.g. with the IP address or name of the server machine. var client = new OpcClient("opc.tcp://*****:*****@"%LocalApplicationData%\My Application\App Certificates"; securityConfiguration.RejectedCertificateStore.StorePath = @"%LocalApplicationData%\My Application\Rejected Certificates"; securityConfiguration.TrustedIssuerCertificates.StorePath = @"%LocalApplicationData%\My Application\Trusted Issuer Certificates"; securityConfiguration.TrustedPeerCertificates.StorePath = @"%LocalApplicationData%\My Application\Trusted Peer Certificates"; //// It is not necessary that all certificate stores have to point to the same root //// directory as above. Each store can also point to a totally different directory. client.Configuration = configuration; // 3rd Way: Directly change the default configuration of the client instance using the // Configuration property. client.Configuration.ClientConfiguration.DefaultSessionTimeout = 300000; // 5 Minutes client.Connect(); client.Disconnect(); // In case you are using the OpcClientApplication class, you can directly configure // your client/application using the Configuration property of the application instance // as the following code does demonstrate. var app = new OpcClientApplication("opc.tcp://localhost:4840/SampleServer"); app.Configuration.ClientConfiguration.DefaultSessionTimeout = 300000; // 5 Minutes app.Run(); }