protected void ReviseSecurityMode(bool firstCall, MessageSecurityMode requestedMode)
{
bool supported = false;
// server may support multiple security modes - check if the one the client used is supported.
if (firstCall && !m_discoveryOnly)
{
foreach (EndpointDescription endpoint in m_endpoints)
{
if (endpoint.SecurityMode == requestedMode)
{
if (requestedMode == MessageSecurityMode.None ||
endpoint.SecurityPolicyUri == m_securityPolicyUri)
{
m_securityMode = endpoint.SecurityMode;
m_selectedEndpoint = endpoint;
supported = true;
break;
}
}
}
}
if (!supported)
{
throw ServiceResultException.Create(StatusCodes.BadSecurityModeRejected, "Security mode is not acceptable to the server.");
}
}