Exemple #1
0
        /// <summary>
        /// Caches application description and list of available endpoints.
        /// </summary>
        private void InitializeApplicationDescription()
        {
            // this method is caches the information the first time a client connects.
            if (m_application == null)
            {
                // the serviceCertificate element in the app.config file controls what certificate is loaded.
                m_serverCertificate = OperationContext.Current.Host.Credentials.ServiceCertificate.Certificate;

                // the URL may be the discovery or the session endpoint. need to store the session endpoint.
                string endpointUrl = OperationContext.Current.Channel.LocalAddress.ToString();

                if (endpointUrl.EndsWith("/discovery", StringComparison.InvariantCulture))
                {
                    endpointUrl = endpointUrl.Substring(0, endpointUrl.Length - "/discovery".Length);
                }

                // The EndpointDescription stores the information specified in the ISessionEndpoint binding.
                // This structure is used in the UA discovery services and allows client applications to
                // discover what security settings are used by the server.

                EndpointDescription endpoint = new EndpointDescription();

                endpoint.EndpointUrl         = endpointUrl;
                endpoint.SecurityMode        = MessageSecurityMode.SignAndEncrypt_3;
                endpoint.SecurityPolicyUri   = SecurityPolicies.Basic128Rsa15;
                endpoint.ServerCertificate   = m_serverCertificate.GetRawCertData();
                endpoint.TransportProfileUri = Profiles.WsHttpXmlTransport;

                endpoint.Server = new ApplicationDescription();
                endpoint.Server.ApplicationUri  = ApplicationUri;
                endpoint.Server.ApplicationType = ApplicationType.Server_0;
                endpoint.Server.DiscoveryUrls   = new ListOfString();
                endpoint.Server.DiscoveryUrls.Add(endpointUrl + "/discovery");

                // no authorization supported at this time.
                UserTokenPolicy userTokenPolicy = new UserTokenPolicy();
                userTokenPolicy.TokenType   = UserTokenType.Anonymous_0;
                endpoint.UserIdentityTokens = new ListOfUserTokenPolicy();
                endpoint.UserIdentityTokens.Add(userTokenPolicy);

                m_application = endpoint.Server;

                // If the server supports multiple bindings it will need multiple EndpointDescriptions. These
                // structures can be constructed automatically from the bindings in the OperationContext object
                // This example simply hard codes the settings so a mismatch between the app.config could cause
                // problems.

                m_endpoints = new ListOfEndpointDescription();
                m_endpoints.Add(endpoint);
            }
        }
Exemple #2
0
        /// <summary>
        /// Caches application description and list of available endpoints.
        /// </summary>
        private void InitializeApplicationDescription()
        {
            // this method is caches the information the first time a client connects.
            if (m_application == null)
            {
                // the serviceCertificate element in the app.config file controls what certificate is loaded.
                m_serverCertificate = OperationContext.Current.Host.Credentials.ServiceCertificate.Certificate;

                // the URL may be the discovery or the session endpoint. need to store the session endpoint.
                string endpointUrl = OperationContext.Current.Channel.LocalAddress.ToString();
                
                if (endpointUrl.EndsWith("/discovery", StringComparison.InvariantCulture))
                {
                    endpointUrl = endpointUrl.Substring(0, endpointUrl.Length - "/discovery".Length);
                }

                // The EndpointDescription stores the information specified in the ISessionEndpoint binding.
                // This structure is used in the UA discovery services and allows client applications to 
                // discover what security settings are used by the server. 

                EndpointDescription endpoint = new EndpointDescription();

                endpoint.EndpointUrl = endpointUrl;
                endpoint.SecurityMode = MessageSecurityMode.SignAndEncrypt_3;
                endpoint.SecurityPolicyUri = SecurityPolicies.Basic128Rsa15;
                endpoint.ServerCertificate = m_serverCertificate.GetRawCertData();
                endpoint.TransportProfileUri = Profiles.WsHttpXmlTransport;

                endpoint.Server = new ApplicationDescription();
                endpoint.Server.ApplicationUri = ApplicationUri;
                endpoint.Server.ApplicationType = ApplicationType.Server_0;
                endpoint.Server.DiscoveryUrls = new ListOfString();
                endpoint.Server.DiscoveryUrls.Add(endpointUrl + "/discovery");

                // no authorization supported at this time.
                UserTokenPolicy userTokenPolicy = new UserTokenPolicy();
                userTokenPolicy.TokenType = UserTokenType.Anonymous_0;
                endpoint.UserIdentityTokens = new ListOfUserTokenPolicy();
                endpoint.UserIdentityTokens.Add(userTokenPolicy);

                m_application = endpoint.Server;

                // If the server supports multiple bindings it will need multiple EndpointDescriptions. These
                // structures can be constructed automatically from the bindings in the OperationContext object
                // This example simply hard codes the settings so a mismatch between the app.config could cause
                // problems.
                
                m_endpoints = new ListOfEndpointDescription();
                m_endpoints.Add(endpoint);
            }
        }