110,566
社区成员
发帖
与我相关
我的任务
分享
public void Connect(string Url)
{
try
{
// Create the configuration.
ApplicationConfiguration configuration = Helpers.CreateClientConfiguration();
// Create the endpoint description.
EndpointDescription endpointDescription = Helpers.CreateEndpointDescription(Url);
// Create the endpoint configuration (use the application configuration to provide default values).
EndpointConfiguration endpointConfiguration = EndpointConfiguration.Create(configuration);
// The default timeout for a requests sent using the channel.
endpointConfiguration.OperationTimeout = 300000;
// Use the pure binary encoding on the wire.
endpointConfiguration.UseBinaryEncoding = true;
// Create the endpoint.
ConfiguredEndpoint endpoint = new ConfiguredEndpoint(null, endpointDescription, endpointConfiguration);
// Create the binding factory.
BindingFactory bindingFactory = BindingFactory.Create(configuration);
// Update endpoint description using the discovery endpoint.
if (endpoint.UpdateBeforeConnect)
{
endpoint.UpdateFromServer(bindingFactory);
endpointDescription = endpoint.Description;
endpointConfiguration = endpoint.Configuration;
}
//endpoint.EndpointUrl = new Uri("opc.tcp://190.160.9.219:4840");
X509Certificate2 clientCertificate = configuration.SecurityConfiguration.ApplicationCertificate.Find();
// Set up a callback to handle certificate validation errors.
configuration.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation);
// Initialize the channel which will be created with the server.
SessionChannel channel = SessionChannel.Create(
configuration,
endpointDescription,
endpointConfiguration,
bindingFactory,
clientCertificate,
null);
// Wrap the channel with the session object.
// This call will fail if the server does not trust the client certificate.
m_Session = new Session(channel, configuration, endpoint);
m_Session.ReturnDiagnostics = DiagnosticsMasks.All;
// Register keep alive callback.
m_Session.KeepAlive += new KeepAliveEventHandler(Session_KeepAlive);
UserIdentity identity = new UserIdentity();
// Create the session. This actually connects to the server.
// Passing null for the user identity will create an anonymous session.
m_Session.Open("ClientUA_1", identity);
}
catch (Exception e)
{
throw e;
}
}
public void Connect(string Url)
{
try
{
// Create the configuration.
ApplicationConfiguration configuration = Helpers.CreateClientConfiguration();
// Create the endpoint description.
EndpointDescription endpointDescription = Helpers.CreateEndpointDescription(Url);
// Create the endpoint configuration (use the application configuration to provide default values).
EndpointConfiguration endpointConfiguration = EndpointConfiguration.Create(configuration);
// The default timeout for a requests sent using the channel.
endpointConfiguration.OperationTimeout = 300000;
// Use the pure binary encoding on the wire.
endpointConfiguration.UseBinaryEncoding = true;
// Create the endpoint.
ConfiguredEndpoint endpoint = new ConfiguredEndpoint(null, endpointDescription, endpointConfiguration);
// Create the binding factory.
BindingFactory bindingFactory = BindingFactory.Create(configuration);
// Update endpoint description using the discovery endpoint.
if (endpoint.UpdateBeforeConnect)
{
endpoint.UpdateFromServer(bindingFactory);
endpointDescription = endpoint.Description;
endpointConfiguration = endpoint.Configuration[code=csharp]
;
}
X509Certificate2 clientCertificate = configuration.SecurityConfiguration.ApplicationCertificate.Find();
// Set up a callback to handle certificate validation errors.
configuration.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation);
// Initialize the channel which will be created with the server.
SessionChannel channel = SessionChannel.Create(
configuration,
endpointDescription,
endpointConfiguration,
bindingFactory,
clientCertificate,
null);
// Wrap the channel with the session object.
// This call will fail if the server does not trust the client certificate.
m_Session = new Session(channel, configuration, endpoint);
m_Session.ReturnDiagnostics = DiagnosticsMasks.All;
// Register keep alive callback.
m_Session.KeepAlive += new KeepAliveEventHandler(Session_KeepAlive);
UserIdentity identity = new UserIdentity();
// Create the session. This actually connects to the server.
// Passing null for the user identity will create an anonymous session.
m_Session.Open("ClientUA_1", identity);
}
catch (Exception e)
{
throw e;
}
}
[/code]