【问题标题】:Connecting to Dynamics CRM configured with IFD without using the SDK在不使用 SDK 的情况下连接到使用 IFD 配置的 Dynamics CRM
【发布时间】:2014-09-18 08:47:23
【问题描述】:

我们最近将 Dynamics CRM 配置为使用 ADFS for IFD。我们正在尝试从 .Net 3.5 连接到它,因此我们无法使用 CRM SDK。下面是我们在配置 IFD 之前使用的代码,它运行良好。

HttpsTransportBindingElement httpTransport = new HttpsTransportBindingElement();              
httpTransport.AuthenticationScheme = System.Net.AuthenticationSchemes.Ntlm;
httpTransport.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
httpTransport.MaxReceivedMessageSize = 1024 * 1024 * 1024;

SecurityBindingElement securityElement = SecurityBindingElement.CreateSspiNegotiationBindingElement(true);

TextMessageEncodingBindingElement textMessageEncoding = new TextMessageEncodingBindingElement();
textMessageEncoding.MaxReadPoolSize = 64;
textMessageEncoding.MaxWritePoolSize = 16;
textMessageEncoding.WriteEncoding = Encoding.UTF8;

CustomBinding customBinding = new CustomBinding(securityElement, textMessageEncoding, httpTransport);
customBinding.OpenTimeout = new TimeSpan(0, 0, 120);
customBinding.ReceiveTimeout = new TimeSpan(0, 0, 120);
customBinding.SendTimeout = new TimeSpan(0, 0, 120);

string remoteAddress = String.Empty;


remoteAddress = "https://" + ServiceUri + "/OrgName/XrmServices/2011/Organization.svc";

ChannelFactory<IOrganizationService> factory = new ChannelFactory<IOrganizationService>(customBinding, remoteAddress);

ClientCredentials loginCredentials = factory.Endpoint.Behaviors.Find<ClientCredentials>();
factory.Endpoint.Behaviors.Remove(loginCredentials);

// step two - instantiate your credentials
loginCredentials = new ClientCredentials();
loginCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(UserName, Password, Domain);
factory.Endpoint.Behaviors.Add(loginCredentials);

IEnumerable<OperationDescription> operations = factory.Endpoint.Contract.Operations;


foreach (OperationDescription operation in operations)
{
    DataContractSerializerOperationBehavior dcsob = operation.Behaviors.Find<DataContractSerializerOperationBehavior>();
    if (dcsob == null)
    {
        dcsob = new DataContractSerializerOperationBehavior(operation);
    }
    operation.Behaviors.Remove(dcsob);
    dcsob.MaxItemsInObjectGraph = 1012 * 1024 * 1024;
    operation.Behaviors.Add(dcsob);
}


_orgProxy = factory.CreateChannel();

现在,当我们尝试使用此代码连接到 CRM 时,它会返回以下错误: &lt;/StackTrace&gt;&lt;ExceptionString&gt;System.ServiceModel.Security.MessageSecurityException: Security processor was unable to find a security header in the message. This might be because the message is an unsecured fault or because there is a binding mismatch between the communicating parties. This can occur if the service is configured for security and the client is not using security.&lt;/ExceptionString&gt;&lt;/Exception&gt;&lt;/TraceRecord&gt;

我的问题是我需要哪些额外的安全标头,以及如何修改绑定以包含它们?

【问题讨论】:

标签: .net-3.5 dynamics-crm-2011 adfs2.0


【解决方案1】:

消息表明该服务已针对安全性进行了配置,而客户端未使用安全性。 要使客户端配置自动生成,可以使用 Add Service Reference 选项,或者使用 SvcUtil.exe 生成代理类。

【讨论】:

    猜你喜欢
    • 2018-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多