An unhandled exception of type 'System.ServiceModel.Security.MessageSecurityException' occurred in Microsoft.Xrm.Sdk.dll
Additional information: An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail.
my code:
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Query;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.ServiceModel.Description;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplicationdate
{
class Program
{
static void Main(string[] args)
{
#region Org Connection
IOrganizationService organizationService = null;
ClientCredentials clientCredentials = new ClientCredentials();
//clientCredentials.UserName.UserName = ConfigurationManager.AppSettings["Username"].ToString();
//clientCredentials.UserName.Password = ConfigurationManager.AppSettings["Password"].ToString();
clientCredentials.UserName.UserName = "trail.onmicrosoft.com";
clientCredentials.UserName.Password = "password";
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// Copy and Paste Organization Service Endpoint Address URL
organizationService = new OrganizationServiceProxy(new Uri("org------.api.crm8.dynamics.com/.../Organization.svc"), null, clientCredentials, null);
#endregion
if (organizationService != null)
{
Console.WriteLine("sucess");
var query = new QueryExpression("crf1b_class")
{
ColumnSet = new ColumnSet("crf1b_name"),
Criteria = new FilterExpression(LogicalOperator.And),
TopCount = 50
};
//query.Criteria.AddCondition("address1_city", ConditionOperator.Equal, "Redmond");
//query.AddOrder("name", OrderType.Ascending);
EntityCollection results = organizationService.RetrieveMultiple(query);
results.Entities.ToList().ForEach(x =>
{
Console.WriteLine(x.Attributes["crf1b_name"]);
});
Console.ReadLine();
}
}
}
}