【问题标题】:WCF crm connection failure, due to unsecured stringWCF crm 连接失败,由于字符串不安全
【发布时间】:2018-07-24 09:25:45
【问题描述】:

<?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;
        }
    }
}

我确定我的登录信息是正确的。我已经为此工作了好几个星期。请有更多知识的人帮忙。

【问题讨论】:

  • 您使用的是哪个版本的 CRM 程序集?
  • @HenrikH 我如何确定这一点,我对 CRM 开发还很陌生?
  • @HenrikH 正在谈论这些:使用系统;使用 System.Collections.Generic;使用 System.ComponentModel;使用 System.Data;使用 System.Drawing;使用 System.Linq;使用 System.Text;使用 System.Threading.Tasks;使用 System.Windows.Forms;使用 MedinetCRM;使用 Microsoft.Xrm.Client;使用 Microsoft.Xrm.Client.Services;使用 System.Configuration;使用 Microsoft.Xrm.Sdk;使用 System.ServiceModel;
  • 是的,我正在考虑 Microsoft.Xrm.Sdk。你能检查一下 DLL 的版本(或者你安装它的 nuget 包)吗?
  • 我解决了。通过管理 Nuget 更新了 Xrm.sdk。

标签: c# dynamics-crm connection-string wcf-binding dynamics-crm-online


【解决方案1】:

该连接方法已被弃用。我建议获取最新的Xrm Tooling NuGet 包。

然后实例化一个CrmServiceClient的实例,它实现了IOrganizationService,还有很多附加方法:

using Microsoft.Xrm.Tooling.Connector;

var svc = new CrmServiceClient(connectionString);

这里是an article,关于从 Xrm.Client 到 CrmServiceClient 的转换。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-24
    • 2015-08-19
    • 1970-01-01
    • 1970-01-01
    • 2015-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多