是否可以在不使用SDK的情况下调用Dynamics CRM 2011的后期绑定WCF组织服务 – 直接定制绑定?
我试图实现一个纯粹的WCF场景,我想调用Dynamics CRM WCF服务,而不依赖于SDK辅助类。 基本上,我想通过.net框架仅使用本机WCF支持,针对Dynamics CRM 2011实施联合身份validation。
我这样做的原因是我想稍后移植到BizTalk。
我已经使用SvcUtil成功生成了代理类,但策略和安全声明的一部分与configuration模式不兼容。 SvcUtilbuild议用代码来build立绑定,这就是我正在做的。
结果代码在这里:
private static void CallWcf() { OrganizationServiceClient client = null; try { // Login Live.com Issuer Binding var wsHttpBinding = new WSHttpBinding(); wsHttpBinding.Security = new WSHttpSecurity(); wsHttpBinding.Security.Mode = SecurityMode.Transport; // Endpoint Binding Elements var securityElement = new TransportSecurityBindingElement(); securityElement.DefaultAlgorithmSuite = SecurityAlgorithmSuite.TripleDes; securityElement.IncludeTimestamp = true; securityElement.KeyEntropyMode = SecurityKeyEntropyMode.CombinedEntropy; securityElement.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10; securityElement.SecurityHeaderLayout = SecurityHeaderLayout.Strict; var securityTokenParameters = new IssuedSecurityTokenParameters(); securityTokenParameters.InclusionMode = SecurityTokenInclusionMode.AlwaysToRecipient; securityTokenParameters.ReferenceStyle = SecurityTokenReferenceStyle.Internal; securityTokenParameters.RequireDerivedKeys = false; securityTokenParameters.TokenType = null; securityTokenParameters.KeyType = SecurityKeyType.SymmetricKey; securityTokenParameters.KeySize = 192; securityTokenParameters.IssuerAddress = new EndpointAddress("https://login.live.com/extSTS.srf"); securityTokenParameters.IssuerMetadataAddress = null; securityTokenParameters.DefaultMessageSecurityVersion = null; securityTokenParameters.IssuerBinding = wsHttpBinding; securityElement.EndpointSupportingTokenParameters.Signed.Add(securityTokenParameters); var textMessageEncodingElement = new TextMessageEncodingBindingElement(); textMessageEncodingElement.MaxReadPoolSize = 64; textMessageEncodingElement.MaxWritePoolSize = 16; textMessageEncodingElement.MessageVersion = MessageVersion.Default; textMessageEncodingElement.WriteEncoding = System.Text.Encoding.UTF8; textMessageEncodingElement.ReaderQuotas.MaxStringContentLength = 8192; textMessageEncodingElement.ReaderQuotas.MaxArrayLength = 16384; textMessageEncodingElement.ReaderQuotas.MaxBytesPerRead = 4096; textMessageEncodingElement.ReaderQuotas.MaxNameTableCharCount = 16384; var httpsTransportElement = new HttpsTransportBindingElement(); httpsTransportElement.ManualAddressing = false; httpsTransportElement.AuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous; CustomBinding binding = new CustomBinding(); binding.Elements.Add(securityElement); binding.Elements.Add(textMessageEncodingElement); binding.Elements.Add(httpsTransportElement); client = new OrganizationServiceClient(binding, new EndpointAddress(EndpointUri)); client.ClientCredentials.UserName.UserName = Username; client.ClientCredentials.UserName.Password = Password; client.Open(); var columnSet = new schemas.microsoft.com.xrm._2011.Contracts.ColumnSet(); var identifier = new Guid("fbf8240e-2c85-e011-ad55-1cc1de0878eb"); columnSet.Columns = new string[] { "name" }; var entity = client.Retrieve("account", identifier, columnSet); } finally { if (client != null) client.Close(); } }
我是联邦身份validation的新手,很难找出许多可用绑定之间的潜在差异,所以我将不胜感激这方面的任何帮助。
这可能是可能的,但是非常复杂。 我们有一个使用Dynamics的项目移植到ADFS,并且需要在刷新令牌(代码窗体autorefreshsecuritytoken.cs,deviceidmanager.cs和SDK中的toolserviceproxies.cs)中添加大量额外的代码,并且仍然在使用SDK。
不要忘记,你还需要在操作系统中安装windows.identification这是另一个function的负载复制。
最后,你总是可以使用JustDecompile或类似的东西来看看SDK在做什么。