상속: IServiceMessage
예제 #1
0
        /// <summary>
        /// Asynchronously calls the CreateSession service.
        /// </summary>
        public virtual IAsyncResult BeginCreateSession(CreateSessionMessage message, AsyncCallback callback, object callbackData)
        {
            try
            {
                // check for bad data.
                if (message == null) throw new ArgumentNullException("message");

                // set the request context.
                SetRequestContext(RequestEncoding.Xml);

                // create handler.
                ProcessRequestAsyncResult result = new ProcessRequestAsyncResult(this, callback, callbackData, 0);
                return result.BeginProcessRequest(SecureChannelContext.Current, message.CreateSessionRequest);
            }
            catch (Exception e)
            {
                throw CreateSoapFault(message.CreateSessionRequest, e);
            }
        }
예제 #2
0
        /// <summary>
        /// The operation contract for the CreateSession service.
        /// </summary>
        public virtual CreateSessionResponseMessage CreateSession(CreateSessionMessage request)
        {
            CreateSessionResponse response = null;

            try
            {
                // OnRequestReceived(message.CreateSessionRequest);

                SetRequestContext(RequestEncoding.Xml);
                response = (CreateSessionResponse)CreateSession(request.CreateSessionRequest);
                // OnResponseSent(response);
                return new CreateSessionResponseMessage(response);
            }
            catch (Exception e)
            {
                Exception fault = CreateSoapFault(request.CreateSessionRequest, e);
                // OnResponseFaultSent(fault);
                throw fault;
            }
        }
예제 #3
0
 /// <summary>
 /// The operation contract for the CreateSession service.
 /// </summary>
 public virtual CreateSessionResponseMessage CreateSession(CreateSessionMessage request)
 {
     try
     {
         SetRequestContext(RequestEncoding.Xml);
         CreateSessionResponse response = (CreateSessionResponse)CreateSession(request.CreateSessionRequest);
         return new CreateSessionResponseMessage(response);
     }
     catch (Exception e)
     {
         throw CreateSoapFault(request.CreateSessionRequest, e);
     }
 }
예제 #4
0
        /// <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);
            }
        }