本文整理汇总了C#中ConfiguredEndpoint.UpdateFromServer方法的典型用法代码示例。如果您正苦于以下问题:C# ConfiguredEndpoint.UpdateFromServer方法的具体用法?C# ConfiguredEndpoint.UpdateFromServer怎么用?C# ConfiguredEndpoint.UpdateFromServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfiguredEndpoint
的用法示例。
在下文中一共展示了ConfiguredEndpoint.UpdateFromServer方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
VariableBrowsePaths = new List<string>();
VariableBrowsePaths.Add("/6:Data/6:Dynamic/6:Scalar/6:Int32Value");
// VariableBrowsePaths.Add("/7:MatrikonOpc Sim Server/7:Simulation Items/7:Bucket Brigade/7:Int1");
// VariableBrowsePaths.Add("/7:MatrikonOPC Sim Server/7:Simulation Items/7:Bucket Brigade/7:Int2");
try
{
// create the configuration.
ApplicationConfiguration configuration = Helpers.CreateClientConfiguration();
// create the endpoint description.
EndpointDescription endpointDescription = Helpers.CreateEndpointDescription();
// 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 = 600000;
// use the pure XML encoding on the wire.
endpointConfiguration.UseBinaryEncoding = true;
// create the endpoint.
ConfiguredEndpoint endpoint = new ConfiguredEndpoint(null, endpointDescription, endpointConfiguration);
// create the binding factory.
ServiceMessageContext messageContext = configuration.CreateMessageContext();
BindingFactory bindingFactory = BindingFactory.Create(configuration, messageContext);
// update endpoint description using the discovery endpoint.
if (endpoint.UpdateBeforeConnect)
{
endpoint.UpdateFromServer(bindingFactory);
Console.WriteLine("Updated endpoint description for url: {0}", endpointDescription.EndpointUrl);
endpointDescription = endpoint.Description;
endpointConfiguration = endpoint.Configuration;
}
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.
ITransportChannel channel = SessionChannel.Create(
configuration,
endpointDescription,
endpointConfiguration,
clientCertificate,
messageContext);
// Wrap the channel with the session object.
// This call will fail if the server does not trust the client certificate.
Session session = new Session(channel, configuration, endpoint, null);
session.ReturnDiagnostics = DiagnosticsMasks.All;
// register keep alive callback.
// session.KeepAlive += new KeepAliveEventHandler(Session_KeepAlive);
// passing null for the user identity will create an anonymous session.
UserIdentity identity = null; // new UserIdentity("iamuser", "password");
// create the session. This actually connects to the server.
session.Open("My Session Name", identity);
//Read some history values:
string str = "";
do
{
Console.WriteLine("Select action from the menu:\n");
Console.WriteLine("\t 0 - Browse");
Console.WriteLine("\t 1 - Update");
Console.WriteLine("\t 2 - ReadRaw");
Console.WriteLine("\t 3 - ReadProcessed");
Console.WriteLine("\t 4 - ReadAtTime");
Console.WriteLine("\t 5 - ReadAttributes");
Console.WriteLine("\t 6 - DeleteAtTime");
Console.WriteLine("\t 7 - DeleteRaw");
Console.WriteLine("\n\tQ - exit\n\n");
str = Console.ReadLine();
Console.WriteLine("\n");
try
{
if (str == "0")
{
Browse(session);
}
else if (str == "1")
HistoryUpdate(session);
else if (str == "2")
//.........这里部分代码省略.........
示例2: DoTest
/// <summary>
/// Runs the test in a background thread.
/// </summary>
private void DoTest(ConfiguredEndpoint endpoint)
{
PerformanceTestResult result = new PerformanceTestResult(endpoint, 100);
result.Results.Add(1, -1);
result.Results.Add(10, -1);
result.Results.Add(50, -1);
result.Results.Add(100, -1);
result.Results.Add(250, -1);
result.Results.Add(500, -1);
try
{
// update the endpoint.
if (endpoint.UpdateBeforeConnect)
{
endpoint.UpdateFromServer();
}
SessionClient client = null;
Uri url = new Uri(endpoint.Description.EndpointUrl);
ITransportChannel channel = SessionChannel.Create(
m_configuration,
endpoint.Description,
endpoint.Configuration,
m_clientCertificate,
m_messageContext);
client = new SessionClient(channel);
List<int> requestSizes = new List<int>(result.Results.Keys);
for (int ii = 0; ii < requestSizes.Count; ii++)
{
// update the progress indicator.
TestProgress((ii * 100) / requestSizes.Count);
lock (m_lock)
{
if (!m_running)
{
break;
}
}
int count = requestSizes[ii];
// initialize request.
RequestHeader requestHeader = new RequestHeader();
requestHeader.ReturnDiagnostics = 5000;
ReadValueIdCollection nodesToRead = new ReadValueIdCollection(count);
for (int jj = 0; jj < count; jj++)
{
ReadValueId item = new ReadValueId();
item.NodeId = new NodeId((uint)jj, 1);
item.AttributeId = Attributes.Value;
nodesToRead.Add(item);
}
// ensure valid connection.
DataValueCollection results = null;
DiagnosticInfoCollection diagnosticInfos = null;
client.Read(
requestHeader,
0,
TimestampsToReturn.Both,
nodesToRead,
out results,
out diagnosticInfos);
if (results.Count != count)
{
throw new ServiceResultException(StatusCodes.BadUnknownResponse);
}
// do test.
DateTime start = DateTime.UtcNow;
for (int jj = 0; jj < result.Iterations; jj++)
{
client.Read(
requestHeader,
0,
TimestampsToReturn.Both,
nodesToRead,
out results,
out diagnosticInfos);
if (results.Count != count)
{
//.........这里部分代码省略.........
示例3: Create
/// <summary>
/// Creates a new communication session with a server by invoking the CreateSession service
/// </summary>
/// <param name="configuration">The configuration for the client application.</param>
/// <param name="endpoint">The endpoint for the server.</param>
/// <param name="updateBeforeConnect">If set to <c>true</c> the discovery endpoint is used to update the endpoint description before connecting.</param>
/// <param name="checkDomain">If set to <c>true</c> then the domain in the certificate must match the endpoint used.</param>
/// <param name="sessionName">The name to assign to the session.</param>
/// <param name="sessionTimeout">The timeout period for the session.</param>
/// <param name="identity">The user identity to associate with the session.</param>
/// <param name="preferredLocales">The preferred locales.</param>
/// <returns>The new session object.</returns>
public static Session Create(
ApplicationConfiguration configuration,
ConfiguredEndpoint endpoint,
bool updateBeforeConnect,
bool checkDomain,
string sessionName,
uint sessionTimeout,
IUserIdentity identity,
IList<string> preferredLocales)
{
endpoint.UpdateBeforeConnect = updateBeforeConnect;
EndpointDescription endpointDescription = endpoint.Description;
// create the endpoint configuration (use the application configuration to provide default values).
EndpointConfiguration endpointConfiguration = endpoint.Configuration;
if (endpointConfiguration == null)
{
endpoint.Configuration = endpointConfiguration = EndpointConfiguration.Create(configuration);
}
// create message context.
ServiceMessageContext messageContext = configuration.CreateMessageContext();
// update endpoint description using the discovery endpoint.
if (endpoint.UpdateBeforeConnect)
{
BindingFactory bindingFactory = BindingFactory.Create(configuration, messageContext);
endpoint.UpdateFromServer(bindingFactory);
endpointDescription = endpoint.Description;
endpointConfiguration = endpoint.Configuration;
}
// checks the domains in the certificate.
if (checkDomain && endpoint.Description.ServerCertificate != null && endpoint.Description.ServerCertificate.Length > 0)
{
CheckCertificateDomain(endpoint);
}
X509Certificate2 clientCertificate = null;
//X509Certificate2Collection clientCertificateChain = null;
if (endpointDescription.SecurityPolicyUri != SecurityPolicies.None)
{
if (configuration.SecurityConfiguration.ApplicationCertificate == null)
{
throw ServiceResultException.Create( StatusCodes.BadConfigurationError, "ApplicationCertificate must be specified." );
}
clientCertificate = configuration.SecurityConfiguration.ApplicationCertificate.Find( true );
if( clientCertificate == null )
{
throw ServiceResultException.Create( StatusCodes.BadConfigurationError, "ApplicationCertificate cannot be found." );
}
//load certificate chain
//clientCertificateChain = new X509Certificate2Collection(clientCertificate);
//List<CertificateIdentifier> issuers = new List<CertificateIdentifier>();
//configuration.CertificateValidator.GetIssuers(clientCertificate, issuers);
//for (int i = 0; i < issuers.Count; i++)
//{
// clientCertificateChain.Add(issuers[i].Certificate);
//}
}
// initialize the channel which will be created with the server.
ITransportChannel channel = SessionChannel.Create(
configuration,
endpointDescription,
endpointConfiguration,
//clientCertificateChain,
clientCertificate,
messageContext);
// create the session object.
Session session = new Session(channel, configuration, endpoint, null);
// create the session.
try
{
session.Open( sessionName, sessionTimeout, identity, preferredLocales, checkDomain );
}
catch
{
session.Dispose();
//.........这里部分代码省略.........
示例4: Run
/// <summary>
/// Runs the testcases against the endpoint.
/// </summary>
/// <param name="endpoint">The endpoint to test.</param>
/// <param name="testcases">The testcases to run.</param>
public void Run(ConfiguredEndpoint endpoint, ServerTestConfiguration testConfiguration)
{
// save the test configuration.
m_testConfiguration = testConfiguration;
m_stopped = false;
// create the binding factory.
m_bindingFactory = BindingFactory.Create(m_configuration, m_messageContext);
while (!m_stopped)
{
try
{
Report("Test run started.");
// update from server.
if (endpoint.UpdateBeforeConnect)
{
endpoint.UpdateFromServer(m_bindingFactory);
Report("Updated endpoint from the discovery endpoint.");
}
// validate the server certificate.
byte[] certificateData = endpoint.Description.ServerCertificate;
try
{
X509Certificate2 certificate = CertificateFactory.Create(certificateData, true);
m_configuration.CertificateValidator.Validate(certificate);
}
catch (ServiceResultException e)
{
if (e.StatusCode != StatusCodes.BadCertificateUntrusted)
{
throw new ServiceResultException(e, StatusCodes.BadCertificateInvalid);
}
// automatically trust the certificate if it is untrusted.
m_configuration.CertificateValidator.Update(m_configuration.SecurityConfiguration);
}
m_defaultEndpoint = endpoint;
// fetch all endpoints from the server.
m_endpoints = GetEndpoints(endpoint);
Report("Fetched all endpoints supported by the server.");
}
catch (Exception e)
{
Report(e, "Could not connect to server");
return;
}
m_endpointCount = 0;
m_totalEndpointCount = 0;
m_testCount = 0;
m_failedTestCount = 0;
m_iterationCount = 0;
m_totalIterationCount = 0;
uint totalCount = 0;
uint failedCount = 0;
uint endpointCount = 0;
if (m_testConfiguration.EndpointSelection != EndpointSelection.Single)
{
EndpointSelection selection = m_testConfiguration.EndpointSelection;
foreach (ConfiguredEndpoint current in m_endpoints.Endpoints)
{
if (IsEndpointSelected(current, selection, false))
{
m_totalEndpointCount++;
}
if (current.Description.EncodingSupport == BinaryEncodingSupport.Optional)
{
if (IsEndpointSelected(current, selection, true))
{
m_totalEndpointCount++;
}
}
}
foreach (ConfiguredEndpoint current in m_endpoints.Endpoints)
{
if (IsEndpointSelected(current, selection, false))
{
m_endpointCount++;
// check if test stopped.
if (m_stopped)
{
break;
}
//.........这里部分代码省略.........
示例5: UpdateEndpoint
/// <summary>
/// Updates an endpoint with information from the server's discovery endpoint.
/// </summary>
/// <param name="endpoint">The server endpoint</param>
private void UpdateEndpoint(ConfiguredEndpoint endpoint)
{
try
{
Cursor = Cursors.WaitCursor;
// create the binding factory if it has not been created yet.
if (m_bindingFactory == null)
{
m_bindingFactory = BindingFactory.Create(m_configuration);
}
endpoint.UpdateFromServer(m_bindingFactory);
}
finally
{
Cursor = Cursors.Default;
}
}
示例6: ExecuteTestSequence
/// <summary>
/// This method executes the test cases for the configured endpoint.
/// In case of multiple channel test cases, this endpoint value is ignored and new
/// endpoint is used to connect to the server specified in test configuration.
/// </summary>
/// <param name="endpoint">This parameter stores an endpoint of the server.</param>
public void ExecuteTestSequence(ConfiguredEndpoint endpoint)
{
lock (m_lock)
{
m_cancel = false;
}
if (endpoint.UpdateBeforeConnect)
{
// create the binding factory if it has not been created yet.
if (m_bindingFactory == null)
{
m_bindingFactory = BindingFactory.Create(m_configuration, m_messageContext);
}
endpoint.UpdateFromServer(m_bindingFactory);
}
ChannelContext selectedChannelContext = null;
selectedChannelContext = InitializeChannel(endpoint, m_logFilePath);
try
{
foreach (TestCase testCase in m_sequenceToExecute.TestCase)
{
if (testCase.SkipTest || testCase.Name.StartsWith(TestCases.SerializerDirect))
{
continue;
}
try
{
TestUtils.ValidateTestCase(testCase, (int)testCase.Start);
}
catch (Exception e)
{
selectedChannelContext.EventLogger.LogErrorEvent(testCase, (int)testCase.Start, e);
if (m_sequenceToExecute.HaltOnError)
{
throw;
}
else
{
continue;
}
}
TestCaseContext testCaseContext = TestUtils.GetExecutionContext(testCase);
try
{
ValidateTestContext(testCaseContext, testCase);
}
catch (Exception e)
{
selectedChannelContext.EventLogger.LogErrorEvent(testCase, (int)testCase.Start, e);
if (m_sequenceToExecute.HaltOnError)
{
throw;
}
else
{
continue;
}
}
if (testCase.Name != TestCases.MultipleChannels)
{
ExecuteTestCase(selectedChannelContext, testCaseContext, testCase);
}
else
{
Uri defaultUrl = new Uri(endpoint.Description.EndpointUrl);
// In case of multiple channel get endpoint urls from the test case file.
List<ChannelContext> channelContextList = new List<ChannelContext>();
List<ConfiguredEndpoint> configuredEndpointList = new List<ConfiguredEndpoint>();
for (int serverCnt = 0; serverCnt < testCaseContext.ServerDetails.Count; serverCnt++)
{
string serverURL = testCaseContext.ServerDetails[serverCnt].Url;
serverURL = serverURL.Replace("localhost", defaultUrl.DnsSafeHost);
//ConfiguredEndpointCollection endpointCollection = new ConfiguredEndpointCollection () ;
//ConfiguredEndpoint serverendpoint = endpointCollection.Create(serverURL);
ConfiguredEndpoint serverendpoint = (ConfiguredEndpoint)endpoint.Clone();
// slow systems may not be able to renew tokens fast enough when overloaded with channels.
serverendpoint.Configuration.SecurityTokenLifetime = 60000;
serverendpoint.Description.EndpointUrl = serverURL;
configuredEndpointList.Add(serverendpoint);
//.........这里部分代码省略.........
示例7: Create
/// <summary>
/// Creates a new communication session with a server by invoking the CreateSession service
/// </summary>
/// <param name="configuration">The configuration for the client application.</param>
/// <param name="endpoint">The endpoint for the server.</param>
/// <param name="updateBeforeConnect">If set to <c>true</c> the discovery endpoint is used to update the endpoint description before connecting.</param>
/// <param name="checkDomain">If set to <c>true</c> then the domain in the certificate must match the endpoint used.</param>
/// <param name="sessionName">The name to assign to the session.</param>
/// <param name="sessionTimeout">The timeout period for the session.</param>
/// <param name="identity">The user identity to associate with the session.</param>
/// <param name="preferredLocales">The preferred locales.</param>
/// <returns>The new session object.</returns>
public static async Task<Session> Create(
ApplicationConfiguration configuration,
ConfiguredEndpoint endpoint,
bool updateBeforeConnect,
bool checkDomain,
string sessionName,
uint sessionTimeout,
IUserIdentity identity,
IList<string> preferredLocales)
{
endpoint.UpdateBeforeConnect = updateBeforeConnect;
EndpointDescription endpointDescription = endpoint.Description;
// create the endpoint configuration (use the application configuration to provide default values).
EndpointConfiguration endpointConfiguration = endpoint.Configuration;
if (endpointConfiguration == null)
{
endpoint.Configuration = endpointConfiguration = EndpointConfiguration.Create(configuration);
}
// create message context.
ServiceMessageContext messageContext = configuration.CreateMessageContext();
// update endpoint description using the discovery endpoint.
if (endpoint.UpdateBeforeConnect)
{
BindingFactory bindingFactory = BindingFactory.Create(configuration, messageContext);
endpoint.UpdateFromServer(bindingFactory);
endpointDescription = endpoint.Description;
endpointConfiguration = endpoint.Configuration;
}
// checks the domains in the certificate.
if (checkDomain && endpoint.Description.ServerCertificate != null && endpoint.Description.ServerCertificate.Length > 0)
{
bool domainFound = false;
X509Certificate2 serverCertificate = new X509Certificate2(endpoint.Description.ServerCertificate);
// check the certificate domains.
IList<string> domains = Utils.GetDomainsFromCertficate(serverCertificate);
if (domains != null)
{
string hostname = endpoint.EndpointUrl.DnsSafeHost;
if (hostname == "localhost" || hostname == "127.0.0.1")
{
hostname = Utils.GetHostName();
}
for (int ii = 0; ii < domains.Count; ii++)
{
if (String.Compare(hostname, domains[ii], StringComparison.CurrentCultureIgnoreCase) == 0)
{
domainFound = true;
break;
}
}
}
if (!domainFound)
{
throw new ServiceResultException(StatusCodes.BadCertificateHostNameInvalid);
}
}
X509Certificate2 clientCertificate = null;
if (endpointDescription.SecurityPolicyUri != SecurityPolicies.None)
{
if (configuration.SecurityConfiguration.ApplicationCertificate == null)
{
throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "ApplicationCertificate must be specified.");
}
clientCertificate = await configuration.SecurityConfiguration.ApplicationCertificate.Find(true);
if (clientCertificate == null)
{
throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "ApplicationCertificate cannot be found.");
}
}
// initialize the channel which will be created with the server.
//.........这里部分代码省略.........
示例8: Create
/// <summary>
/// Creates a new communication session with a server by invoking the CreateSession service
/// </summary>
/// <param name="configuration">The configuration for the client application.</param>
/// <param name="endpoint">The endpoint for the server.</param>
/// <param name="updateBeforeConnect">If set to <c>true</c> the discovery endpoint is used to update the endpoint description before connecting.</param>
/// <param name="checkDomain">If set to <c>true</c> then the domain in the certificate must match the endpoint used.</param>
/// <param name="sessionName">The name to assign to the session.</param>
/// <param name="sessionTimeout">The timeout period for the session.</param>
/// <param name="identity">The user identity to associate with the session.</param>
/// <param name="preferredLocales">The preferred locales.</param>
/// <returns>The new session object.</returns>
public static async Task<Session> Create(
ApplicationConfiguration configuration,
ConfiguredEndpoint endpoint,
bool updateBeforeConnect,
bool checkDomain,
string sessionName,
uint sessionTimeout,
IUserIdentity identity,
IList<string> preferredLocales)
{
endpoint.UpdateBeforeConnect = updateBeforeConnect;
EndpointDescription endpointDescription = endpoint.Description;
// create the endpoint configuration (use the application configuration to provide default values).
EndpointConfiguration endpointConfiguration = endpoint.Configuration;
if (endpointConfiguration == null)
{
endpoint.Configuration = endpointConfiguration = EndpointConfiguration.Create(configuration);
}
// create message context.
ServiceMessageContext messageContext = configuration.CreateMessageContext();
// update endpoint description using the discovery endpoint.
if (endpoint.UpdateBeforeConnect)
{
endpoint.UpdateFromServer();
endpointDescription = endpoint.Description;
endpointConfiguration = endpoint.Configuration;
}
// checks the domains in the certificate.
if (checkDomain && endpoint.Description.ServerCertificate != null && endpoint.Description.ServerCertificate.Length > 0)
{
CheckCertificateDomain(endpoint);
}
X509Certificate2 clientCertificate = null;
if (endpointDescription.SecurityPolicyUri != SecurityPolicies.None)
{
if (configuration.SecurityConfiguration.ApplicationCertificate == null)
{
throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "ApplicationCertificate must be specified.");
}
clientCertificate = await configuration.SecurityConfiguration.ApplicationCertificate.Find(true);
if (clientCertificate == null)
{
throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "ApplicationCertificate cannot be found.");
}
}
// initialize the channel which will be created with the server.
ITransportChannel channel = SessionChannel.Create(
configuration,
endpointDescription,
endpointConfiguration,
clientCertificate,
messageContext);
// create the session object.
Session session = new Session(channel, configuration, endpoint, null);
// create the session.
try
{
session.Open(sessionName, sessionTimeout, identity, preferredLocales, checkDomain);
}
catch (Exception e)
{
session.Dispose();
throw e;
}
return session;
}