<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="microsoft.xrm.client" type="Microsoft.Xrm.Client.Configuration.CrmSection, Microsoft.Xrm.Client"/>
</configSections>
<connectionStrings>
<add name="Medinet" connectionString ="AuthType=Office365;Url=https://medinetdevsandbox.crm11.dynamics.com; Username=victor@******8;Password=*******"/>
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
我的错误是:
System.ServiceModel.Security.MessageSecurityException:'一个不安全的 或从另一方收到错误的安全故障。看到 内部FaultException,以获取故障代码和详细信息。” FaultException:身份验证失败。
我的.CS文件如下:
namespace DemoLibrary
{
public partial class Nurses : Form
{
//private static OrganizationService _orgService;
//private static IOrganizationService service;
public Nurses()
{
InitializeComponent();
service();
//GetOrgService();
}
private void nurseRegistrationBtn_Click(object sender, EventArgs e)
{
//var orgContext = new MedinetCRMService(GetOrgService());
var nurse = new new_nurse
{
new_FirstName = firstNameTextBox3.Text.ToString(),
new_Surname = lastNametextBox2.Text.ToString()
};
if (GendercomboBox1.SelectedIndex == 0)
{
nurse.new_Gender = new OptionSetValue(0);
}
else
nurse.new_Gender = new OptionSetValue(1);
new_hospital hospital = new new_hospital();
hospital.new_name = "Birmingham Community Trust";
Guid hospitalId = (Guid)service().Create(hospital);
//orgContext.AddObject(hospital);
//Guid hospitalID = (Guid)hospital.Id;
CrmEntityReference hospitalReference = new CrmEntityReference(hospital.LogicalName, hospitalId);
nurse.new_name = hospitalReference.ToString();
//orgContext.AddObject(nurse);
//orgContext.SaveChanges();
service().Create(nurse);
MessageBox.Show("Successfully added a Nurse to CRM");
}
// public static OrganizationService GetOrgService()
// {
// if (_orgService == null)
// {
// CrmConnection connection = CrmConnection.Parse(ConfigurationManager.ConnectionStrings["Medinet"].ConnectionString);
// //CrmConnection connection = CrmConnection.Parse( "Url=https://medinetdevsandbox.crm11.dynamics.com; Domain=Medinet; Username=; Password=G;");
// _orgService = new OrganizationService(connection);
// }
// return _orgService;
// }
public static IOrganizationService service()
{
//WSHttpBinding b = new WSHttpBinding();
//b.Security.Mode = SecurityMode.Transport;
//b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
//string connString = "Url=https://medinetdevsandbox.crm11.dynamics.com; Domain=Medinet; Username=victor; Password=;";
CrmConnection connection = new CrmConnection("Medinet");
IOrganizationService service = new OrganizationService(connection);
return service;
}
}
}
我确定我的登录信息正确无误。我已经参加了好几个星期了。有更多知识的人请帮助。
答案 0 :(得分:1)
不建议使用该连接方法。我建议您获取最新的Xrm Tooling NuGet软件包。
然后实例化一个CrmServiceClient实例,该实例实现IOrganizationService
,并具有许多其他方法:
using Microsoft.Xrm.Tooling.Connector;
var svc = new CrmServiceClient(connectionString);
这是an article,关于从Xrm.Client到CrmServiceClient的过渡。