コード例 #1
0
ファイル: Subscription.cs プロジェクト: yuriik83/UA-.NET
 /// <summary>
 /// Creates the subscription.
 /// </summary>
 public void Create(
     Session session,
     NodeManager nodeManager,
     double publishingInterval,
     uint lifetimeCount,
     uint keepAliveCount,
     uint maxNotificationCount,
     bool publishingEnabled,
     byte priority,
     out uint subscriptionId,
     out double revisedPublishingInterval,
     out uint revisedLifetimeCount,
     out uint revisedKeepAliveCount)
 {
     lock (m_lock)
     {
         m_session = session;
         m_nodeManager = nodeManager;
         m_subscriptionId = subscriptionId = (uint)Interlocked.Increment(ref m_subscriptionCounter);
         m_publishingInterval = revisedPublishingInterval = publishingInterval;
         m_lifetimeCount = revisedLifetimeCount = lifetimeCount;
         m_keepAliveCount = revisedKeepAliveCount = keepAliveCount;
         m_maxNotificationCount = maxNotificationCount;
         m_publishingEnabled = publishingEnabled;
         m_priority = priority;
         m_lastPublishTime = 0;
         m_nextKeepAliveTime = (long)(DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond + m_publishingInterval * m_keepAliveCount);
     }
 }
コード例 #2
0
ファイル: MyServer.cs プロジェクト: yuriik83/UA-.NET
        /// <summary>
        /// Creates a session with the server that is independent of the network connection.
        /// </summary>
        public CreateSessionResponseMessage CreateSession(CreateSessionMessage request)
        {
            try
            {
                lock (m_lock)
                {
                    InitializeApplicationDescription();

                    // create a new session object.
                    Session session = new Session();

                    NodeId sessionId;
                    NodeId authenticationToken;
                    byte[] serverNonce;
                    double revisedSessionTimeout;

                    EndpointDescription endpoint = m_endpoints[0];

                    // the session object validates the incoming parameters and produces faults on error.
                    session.Create(
                        endpoint,
                        request.ClientDescription,
                        request.ClientCertificate,
                        request.SessionName,
                        request.RequestedSessionTimeout,
                        out sessionId,
                        out authenticationToken,
                        out serverNonce,
                        out revisedSessionTimeout);

                    // save the session.
                    m_sessions.Add(authenticationToken.Identifier, session);

                    // the server application must authenticate itself to the client by providing a signature.
                    // this process is redundant for applications using WS-SecureConversation with mutual certificate 
                    // exchange, however, the UA specification requires this step to ensure that secure channel 
                    // technologies such as machine-to-machine VPNs can be used instead without sacrificing the 
                    // ability to identify the remote applications.

                    byte[] dataToSign = SecurityUtils.Append(request.ClientCertificate, request.ClientNonce);

                    SignatureData serverSignature = SecurityUtils.Sign(
                        m_serverCertificate,
                        endpoint.SecurityPolicyUri,
                        dataToSign);

                    // contruct the response.
                    CreateSessionResponseMessage response = new CreateSessionResponseMessage();

                    response.ResponseHeader = CreateResponseHeader(request.RequestHeader);
                    response.SessionId = sessionId;
                    response.AuthenticationToken = authenticationToken;
                    response.MaxRequestMessageSize = request.MaxResponseMessageSize;
                    response.RevisedSessionTimeout = revisedSessionTimeout;
                    response.ServerNonce = serverNonce;
                    response.ServerCertificate = m_serverCertificate.GetRawCertData();
                    response.ServerSignature = serverSignature;
                    response.ServerEndpoints = m_endpoints;
                    response.ServerSoftwareCertificates = new ListOfSignedSoftwareCertificate();

                    return response;
                }
            }
            catch (Exception e)
            {
                throw CreateSoapFault(request.RequestHeader, e);
            }
        }