本文整理汇总了C#中ApplicationConfiguration.CreateMessageContext方法的典型用法代码示例。如果您正苦于以下问题:C# ApplicationConfiguration.CreateMessageContext方法的具体用法?C# ApplicationConfiguration.CreateMessageContext怎么用?C# ApplicationConfiguration.CreateMessageContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApplicationConfiguration
的用法示例。
在下文中一共展示了ApplicationConfiguration.CreateMessageContext方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestClient
/// <summary>
/// This constructor loads the configuration.
/// </summary>
/// <remarks> It loads Client configuration, test configuration and
/// initializes contexts for vendor namespaces. </remarks>
public TestClient(ApplicationConfiguration configuration)
{
m_configuration = configuration;
LoadTestConfiguration(null);
m_messageContext = Compare.MessageContext = m_configuration.CreateMessageContext();
TestUtils.InitializeContexts(m_messageContext);
}
示例2: ShowDialog
/// <summary>
/// Displays the dialog.
/// </summary>
public EndpointDescription ShowDialog(
ApplicationConfiguration configuration,
ConfiguredEndpointCollection endpoints,
X509Certificate2 clientCertificate)
{
m_configuration = configuration;
m_endpoints = endpoints;
m_messageContext = configuration.CreateMessageContext();
m_clientCertificate = clientCertificate;
m_running = false;
m_filePath = @".\perftest.csv";
EndpointSelectorCTRL.Initialize(m_endpoints, configuration);
lock (m_lock)
{
OkBTN.Enabled = m_running = false;
}
// show dialog.
if (ShowDialog() != DialogResult.OK)
{
return null;
}
return null;
}
示例3: SampleClientForm
public SampleClientForm(
ApplicationInstance application,
ClientForm masterForm,
ApplicationConfiguration configuration)
:
base(configuration.CreateMessageContext(), application, masterForm, configuration)
{
InitializeComponent();
if (!configuration.SecurityConfiguration.AutoAcceptUntrustedCertificates)
{
configuration.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation);
}
}
示例4: SamplePublisherForm
public SamplePublisherForm(
ApplicationInstance application,
Opc.Ua.Sample.Controls.PublisherForm masterForm,
ApplicationConfiguration configuration)
: base(configuration.CreateMessageContext(), application, masterForm, configuration)
{
InitializeComponent();
base.BrowseCTRL.MethodCalled += new Opc.Ua.Sample.Controls.MethodCalledEventHandler(BrowseCTRL_MethodCalled);
if (!configuration.SecurityConfiguration.AutoAcceptUntrustedCertificates)
{
configuration.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation);
}
}
示例5: ShowDialog
/// <summary>
/// Displays the dialog.
/// </summary>
public ITransportChannel ShowDialog(
ApplicationConfiguration configuration,
EndpointDescriptionCollection endpoints)
{
if (endpoints == null) throw new ArgumentNullException("endpoints");
if (configuration == null) throw new ArgumentNullException("configuration");
m_endpoints = endpoints;
m_configuration = configuration;
m_messageContext = configuration.CreateMessageContext();
EndpointCB.Items.Clear();
foreach (EndpointDescription endpoint in endpoints)
{
EndpointCB.Items.Add(endpoint.EndpointUrl);
}
if (EndpointCB.Items.Count > 0)
{
EndpointCB.SelectedIndex = 0;
}
OperationTimeoutNC.Value = configuration.TransportQuotas.OperationTimeout;
MaxMessageSizeNC.Value = configuration.TransportQuotas.MaxMessageSize;
MaxArrayLengthNC.Value = configuration.TransportQuotas.MaxArrayLength;
MaxStringLengthNC.Value = configuration.TransportQuotas.MaxStringLength;
MaxByteStringLengthNC.Value = configuration.TransportQuotas.MaxByteStringLength;
if (ShowDialog() != DialogResult.OK)
{
return null;
}
// return the channel.
return m_channel;
}
示例6: OnServerStarting
/// <summary>
/// Called before the server starts.
/// </summary>
/// <param name="configuration">The object that stores the configurable configuration information for a UA application.</param>
protected virtual void OnServerStarting(ApplicationConfiguration configuration)
{
// fetch properties and configuration.
Configuration = configuration;
ServerProperties = LoadServerProperties();
// ensure at least one security policy exists.
if (configuration.ServerConfiguration != null)
{
if (configuration.ServerConfiguration.SecurityPolicies.Count == 0)
{
configuration.ServerConfiguration.SecurityPolicies.Add(new ServerSecurityPolicy());
}
// ensure at least one user token policy exists.
if (configuration.ServerConfiguration.UserTokenPolicies.Count == 0)
{
UserTokenPolicy userTokenPolicy = new UserTokenPolicy();
userTokenPolicy.TokenType = UserTokenType.Anonymous;
userTokenPolicy.PolicyId = userTokenPolicy.TokenType.ToString();
configuration.ServerConfiguration.UserTokenPolicies.Add(userTokenPolicy);
}
}
// load the instance certificate.
if (configuration.SecurityConfiguration.ApplicationCertificate != null)
{
InstanceCertificate = configuration.SecurityConfiguration.ApplicationCertificate.Find(true);
}
if (InstanceCertificate == null)
{
throw new ServiceResultException(
StatusCodes.BadConfigurationError,
"Server does not have an instance certificate assigned.");
}
if (!InstanceCertificate.HasPrivateKey)
{
throw new ServiceResultException(
StatusCodes.BadConfigurationError,
"Server does not have access to the private key for the instance certificate.");
}
//load certificate chain
//InstanceCertificateChain = new X509Certificate2Collection(InstanceCertificate);
//List<CertificateIdentifier> issuers = new List<CertificateIdentifier>();
//configuration.CertificateValidator.GetIssuers(InstanceCertificate, issuers);
//for (int i = 0; i < issuers.Count; i++)
//{
// InstanceCertificateChain.Add(issuers[i].Certificate);
//}
// use the message context from the configuration to ensure the channels are using the same one.
MessageContext = configuration.CreateMessageContext();
// assign a unique identifier if none specified.
if (String.IsNullOrEmpty(configuration.ApplicationUri))
{
configuration.ApplicationUri = Utils.GetApplicationUriFromCertficate(InstanceCertificate);
if (String.IsNullOrEmpty(configuration.ApplicationUri))
{
configuration.ApplicationUri = Utils.Format(
"http://{0}/{1}/{2}",
System.Net.Dns.GetHostName(),
configuration.ApplicationName,
Guid.NewGuid());
}
}
// initialize namespace table.
MessageContext.NamespaceUris = new NamespaceTable();
MessageContext.NamespaceUris.Append(configuration.ApplicationUri);
// assign an instance name.
if (String.IsNullOrEmpty(configuration.ApplicationName) && InstanceCertificate != null)
{
configuration.ApplicationName = InstanceCertificate.GetNameInfo(X509NameType.DnsName, false);
}
// save the certificate validator.
CertificateValidator = configuration.CertificateValidator;
}
示例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 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();
//.........这里部分代码省略.........
示例8: Create
public static BindingFactory Create(ApplicationConfiguration configuration)
{
return Create(configuration, configuration.CreateMessageContext());
}
示例9: CreateSession
/// <summary>
/// Creates a session.
/// </summary>
private Session CreateSession(
ApplicationConfiguration configuration,
BindingFactory bindingFactory,
ConfiguredEndpoint endpoint,
IUserIdentity identity)
{
Report("Creating new Session with URL = {0}", endpoint.EndpointUrl);
// Initialize the channel which will be created with the server.
ITransportChannel channel = SessionChannel.Create(
configuration,
endpoint.Description,
endpoint.Configuration,
configuration.SecurityConfiguration.ApplicationCertificate.Find(true),
configuration.CreateMessageContext());
// Wrap the channel with the session object.
Session session = new Session(channel, configuration, endpoint, null);
session.ReturnDiagnostics = DiagnosticsMasks.All;
// register keep alive callback.
session.KeepAlive += new KeepAliveEventHandler(Session_KeepAlive);
// create the user identity.
if (identity == null)
{
if (endpoint.Description.UserIdentityTokens.Count > 0)
{
identity = CreateUserIdentity(endpoint.Description.UserIdentityTokens[0]);
}
}
// Create the session. This actually connects to the server.
session.Open(Guid.NewGuid().ToString(), identity);
Report("Successfully created new Session.");
// return the session.
return session;
}
示例10: InitializeDiscovery
/// <summary>
/// Adds the discovery url to the hosts.
/// </summary>
/// <param name="configuration">The configuration.</param>
/// <param name="discoveryUrls">The discovery urls.</param>
public virtual void InitializeDiscovery(
ApplicationConfiguration configuration,
StringCollection discoveryUrls)
{
// create the binding factory.
BindingFactory bindingFactory = BindingFactory.Create(configuration, configuration.CreateMessageContext());
EndpointConfiguration endpointConfiguration = EndpointConfiguration.Create(configuration);
foreach (string discoveryUrl in discoveryUrls)
{
// parse discovery url.
Uri url = Utils.ParseUri(discoveryUrl);
if (url == null)
{
continue;
}
// create endpoint.
if (url.PathAndQuery.EndsWith("/discovery"))
{
Binding binding = bindingFactory.Create(url.Scheme, endpointConfiguration);
this.AddServiceEndpoint(typeof(IDiscoveryEndpoint), binding, url, url);
}
}
}
示例11: 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.
//.........这里部分代码省略.........
示例12: 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;
}