Endpoint configuration in Microsoft Dynamics CRM 2011 Plugins

Endpoint configuration in Microsoft Dynamics CRM 2011 Plugins

One thing to know when working with CRM Plugins is that there is no associated config file.

If your plugin references a web service and you need to configure an endpoint, you will have to to it by code.

Here is an example to reach Sharepoint’s Document Workspace Web service in a CRM Plugin (most are default config values).

BasicHttpBinding binding = new BasicHttpBinding();

binding.Name = “DwsServiceBinding”;

binding.CloseTimeout = new TimeSpan(0, 1, 0);
binding.OpenTimeout = new TimeSpan(0, 1, 0);
binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
binding.SendTimeout = new TimeSpan(0, 1, 0);
binding.AllowCookies = false;
binding.BypassProxyOnLocal = false;
binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
binding.MaxBufferSize = 65536;
binding.MaxBufferPoolSize = 524288;
binding.MaxReceivedMessageSize = 65536;
binding.MessageEncoding = WSMessageEncoding.Text;
binding.TextEncoding = Encoding.UTF8;
binding.TransferMode = TransferMode.Buffered;
binding.UseDefaultWebProxy = true;

binding.ReaderQuotas.MaxDepth = 32;
binding.ReaderQuotas.MaxStringContentLength = 8192;
binding.ReaderQuotas.MaxArrayLength = 16384;
binding.ReaderQuotas.MaxBytesPerRead = 4096;
binding.ReaderQuotas.MaxNameTableCharCount = 16384;

binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
binding.Security.Transport.Realm = “”;
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

EndpointAddress endPointAddress = new EndpointAddress(“http://sharepoint:1234/_vti_bin/Dws.asmx”);

DwsServiceClient client = new DwsServiceClient(binding, endPointAddress);
client.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(“username”, “password”, “domain”);
client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Identification;

Michaël Braun
No Comments

Post a Comment

Comment
Name
Email
Website